Fixing issues in resolving the configuration resolving.

feature/appm-store/pbac
sinthuja 8 years ago
parent 242cf06f42
commit fd18ab711c

@ -80,19 +80,11 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<systemPropertyVariables>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-surefire-plugin</artifactId>-->
<!--<version>2.18</version>-->
<!--</plugin>-->
</plugins>
</build>
@ -114,6 +106,11 @@
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>

@ -18,17 +18,19 @@
*/
package org.wso2.carbon.device.application.mgt.core.config;
import org.wso2.carbon.device.application.mgt.core.config.extensions.Extension;
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "ApplicationManagementConfiguration")
public class Configurations {
public class Configuration {
private String datasourceName;
private List<Extension> extensionsConfig;
private List<Extension> extensions;
@XmlElement(name = "DatasourceName", required = true)
public String getDatasourceName() {
@ -39,13 +41,14 @@ public class Configurations {
this.datasourceName = datasourceName;
}
@XmlElement(name = "Extensions", required = false)
@XmlElementWrapper(name = "Extensions")
@XmlElement(name = "Extension")
public List<Extension> getExtensions() {
return extensionsConfig;
return extensions;
}
public void setExtensionsConfig(List<Extension> extensionsConfig) {
this.extensionsConfig = extensionsConfig;
public void setExtensions(List<Extension> extensions) {
this.extensions = extensions;
}
}

@ -22,9 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.core.config.extensions.Extension;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@ -32,13 +30,11 @@ import java.io.File;
public class ConfigurationManager {
private final String applicationMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
Constants.APPLICATION_CONFIG_XML_FILE;
private static final Log log = LogFactory.getLog(ConfigurationManager.class);
private Configurations configuration;
private Configuration configuration;
private static String configPath;
private static ConfigurationManager configurationManager;
@ -62,20 +58,30 @@ public class ConfigurationManager {
return configurationManager;
}
public static synchronized void setConfigLocation(String configPath) throws InvalidConfigurationException {
if (ConfigurationManager.configPath == null) {
ConfigurationManager.configPath = configPath;
} else {
throw new InvalidConfigurationException("Configuration path " + configPath + " is already defined");
}
}
private void initConfig() throws ApplicationManagementException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Configurations.class);
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
this.configuration = (Configurations) unmarshaller.unmarshal(new File(applicationMgtConfigXMLPath));
if (configPath == null) {
configPath = Constants.DEFAULT_CONFIG_FILE_LOCATION;
}
this.configuration = (Configuration) unmarshaller.unmarshal(new File(configPath));
} catch (Exception e) {
log.error(e);
throw new InvalidConfigurationException("Error occurred while initializing application config: "
+ applicationMgtConfigXMLPath, e);
+ configPath, e);
}
}
public Configurations getConfiguration() {
public Configuration getConfiguration() {
return configuration;
}

@ -16,14 +16,10 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.config.extensions;
package org.wso2.carbon.device.application.mgt.core.config;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.*;
import java.util.List;
import java.util.Map;
@XmlRootElement(name = "Extension")
public class Extension {
@ -43,7 +39,7 @@ public class Extension {
this.name = name;
}
@XmlElement(name = "ClassName", nillable = false)
@XmlElement(name = "ClassName")
public String getClassName() {
return className;
}
@ -52,7 +48,8 @@ public class Extension {
this.className = className;
}
@XmlElement(name = "Parameters", nillable = true)
@XmlElementWrapper(name = "Parameters")
@XmlElement(name = "Parameter")
public List<Parameter> getParameters() {
return parameters;
}
@ -61,10 +58,10 @@ public class Extension {
this.parameters = parameters;
}
public boolean equals(Object anotherObj){
if (anotherObj instanceof Extension){
public boolean equals(Object anotherObj) {
if (anotherObj instanceof Extension) {
Extension anExt = (Extension) anotherObj;
if (anExt.getName().contentEquals(this.getName())){
if (anExt.getName().contentEquals(this.getName())) {
return true;
}
}

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.config.extensions;
package org.wso2.carbon.device.application.mgt.core.config;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@ -16,15 +16,14 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.extensions.appupload;
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationUploadManager;
public class AppUploadManagerImpl implements ApplicationUploadManager {
public class ApplicationUploadManagerImpl implements ApplicationUploadManager {
public AppUploadManagerImpl(String a, String b){
//do a
}
public ApplicationUploadManagerImpl(String uploadPath){
}
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
public class CategoryManagerImpl implements CategoryManager {
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
public class CommentsManagerImpl implements CommentsManager {
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
public class LifecycleStateManagerImpl implements LifecycleStateManager {
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
public class PlatformManagerImpl implements PlatformManager {
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
public class SubscriptionManagerImpl implements SubscriptionManager {
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
public class VisibilityManagerImpl implements VisibilityManager{
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager;
public class VisibilityTypeManagerImpl implements VisibilityTypeManager {
}

@ -23,7 +23,8 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.extensions.Extension;
import org.wso2.carbon.device.application.mgt.core.config.Extension;
import java.lang.reflect.Constructor;
public class ApplicationManagementUtil {
@ -90,17 +91,22 @@ public class ApplicationManagementUtil {
return getInstance(extension, ApplicationUploadManager.class);
}
private static <T> T getInstance(Extension extension, Class<T> cls) throws InvalidConfigurationException {
private static <T> T getInstance(Extension extension, Class<T> cls) throws InvalidConfigurationException {
try {
Class theClass = Class.forName(extension.getClassName());
Class theClass = Class.forName(extension.getClassName());
Class[] types = new Class[extension.getParameters().size()];
Object[] paramValues = new String[extension.getParameters().size()];
for (int i = 0; i < extension.getParameters().size(); i++) {
types[i] = String.class;
paramValues[i] = extension.getParameters().get(i).getValue();
if (extension.getParameters() != null && extension.getParameters().size() > 0) {
for (int i = 0; i < extension.getParameters().size(); i++) {
types[i] = String.class;
paramValues[i] = extension.getParameters().get(i).getValue();
}
Constructor<T> constructor = theClass.getConstructor(types);
return constructor.newInstance(paramValues);
} else {
Constructor<T> constructor = theClass.getConstructor(types);
return constructor.newInstance();
}
Constructor<T> constructor = theClass.getConstructor(types);
return constructor.newInstance(paramValues);
} catch (Exception e) {
throw new InvalidConfigurationException("Unable to get instance of extension - " + extension.getName()
+ " , for class - " + extension.getClassName(), e);

@ -18,14 +18,22 @@
*/
package org.wso2.carbon.device.application.mgt.core.util;
import org.wso2.carbon.utils.CarbonUtils;
import java.io.File;
public class Constants {
public static final String APPLICATION_CONFIG_XML_FILE = "application-mgt.xml";
public static final String DEFAULT_CONFIG_FILE_LOCATION = CarbonUtils.getCarbonConfigDirPath() + File.separator +
Constants.APPLICATION_CONFIG_XML_FILE;
public static final class DataBaseTypes {
private DataBaseTypes() {
throw new AssertionError();
}
public static final String DB_TYPE_MYSQL = "MySQL";
public static final String DB_TYPE_ORACLE = "Oracle";
public static final String DB_TYPE_MSSQL = "Microsoft SQL Server";

@ -0,0 +1,41 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core;
import org.junit.BeforeClass;
import org.junit.Test;
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import java.io.File;
public class ConfigurationTest {
@BeforeClass
public static void init() throws InvalidConfigurationException {
File configPath = new File("src/test/resources/application-mgt.xml");
ConfigurationManager.setConfigLocation(configPath.getAbsolutePath());
}
@Test
public void validateConfiguration() {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Configuration configuration = configurationManager.getConfiguration();
}
}

@ -1,16 +1,61 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<ApplicationManagementConfiguration>
<!-- Application Mgt DB schema -->
<DatasourceName>jdbc/APPM_DS</DatasourceName>
<Extensions>
<Extension name="ApplicationUploadExtension">
<ClassName>org.wso2.carbon.device.application.mgt.extensions.appupload.AppUploadManagerImpl</ClassName>
<Extension name="ApplicationUploadManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationUploadManagerImpl</ClassName>
<Parameters>
<Parameter name="UploadPath">repository/resources/mobileapps</Parameter>
</Parameters>
</Extension>
<Extension name="ApplicationManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl</ClassName>
</Extension>
<Extension name="ApplicationReleaseManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationReleaseManagerImpl</ClassName>
</Extension>
<Extension name="CategoryManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.CategoryManagerImpl</ClassName>
</Extension>
<Extension name="CommentsManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.CommentsManagerImpl</ClassName>
</Extension>
<Extension name="LifecycleStateManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.LifecycleStateManagerImpl</ClassName>
</Extension>
<Extension name="PlatformManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.PlatformManagerImpl</ClassName>
</Extension>
<Extension name="SubscriptionManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityTypeManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityTypeManagerImpl</ClassName>
</Extension>
</Extensions>
</ApplicationManagementConfiguration>

@ -28,7 +28,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>application-mgt</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Application Management Component</name>
<description>WSO2 Carbon - Application Management Component</description>
@ -39,7 +38,7 @@
<module>org.wso2.carbon.device.application.mgt.common</module>
<module>org.wso2.carbon.device.application.mgt.api</module>
<module>org.wso2.carbon.device.application.mgt.ui</module>
<module>org.wso2.carbon.device.application.mgt.extensions</module>
<!--<module>org.wso2.carbon.device.application.mgt.extensions</module>-->
</modules>

@ -1,16 +1,60 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<ApplicationManagementConfigurations>
<!--
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<ApplicationManagementConfiguration>
<!-- Application Mgt DB schema -->
<DatasourceName>jdbc/APPM_DS</DatasourceName>
<Extensions>
<Extension name="ApplicationUploadExtension">
<ClassName>org.wso2.carbon.device.application.mgt.extensions.appupload.AppUploadManagerImpl</ClassName>
<Extension name="ApplicationUploadManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationUploadManagerImpl</ClassName>
<Parameters>
<Parameter name="UploadPath">repository/resources/mobileapps</Parameter>
</Parameters>
</Extension>
<Extension name="ApplicationManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl</ClassName>
</Extension>
<Extension name="ApplicationReleaseManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationReleaseManagerImpl</ClassName>
</Extension>
<Extension name="CategoryManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.CategoryManagerImpl</ClassName>
</Extension>
<Extension name="CommentsManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.CommentsManagerImpl</ClassName>
</Extension>
<Extension name="LifecycleStateManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.LifecycleStateManagerImpl</ClassName>
</Extension>
<Extension name="PlatformManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.PlatformManagerImpl</ClassName>
</Extension>
<Extension name="SubscriptionManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityTypeManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityTypeManagerImpl</ClassName>
</Extension>
</Extensions>
</ApplicationManagementConfigurations>
</ApplicationManagementConfiguration>

@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except

Loading…
Cancel
Save