Refactoring the APP manager code, second phase.

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

@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import javax.ws.rs.core.Response;
@ -35,24 +35,24 @@ public class APIUtil {
private static Log log = LogFactory.getLog(APIUtil.class);
private static ApplicationManagementServiceFactory applicationManagementServiceFactory;
private static ApplicationManager applicationManager;
public static ApplicationManagementServiceFactory getApplicationManagementServiceFactory() {
if (applicationManagementServiceFactory == null) {
public static ApplicationManager getApplicationManagemer() {
if (applicationManager == null) {
synchronized (APIUtil.class) {
if (applicationManagementServiceFactory == null) {
if (applicationManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
applicationManagementServiceFactory =
(ApplicationManagementServiceFactory) ctx.getOSGiService(ApplicationManagementServiceFactory.class, null);
if (applicationManagementServiceFactory == null) {
String msg = "Application Management provider service has not initialized.";
applicationManager =
(ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
if (applicationManager == null) {
String msg = "Application Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return applicationManagementServiceFactory;
return applicationManager;
}
public static Response getResponse(ApplicationManagementException ex, Response.Status status) {

@ -1,44 +0,0 @@
/*
* 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.api;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class APIOriginFilter implements Filter {
//TODO: check no config option.
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
chain.doFilter(request, response);
}
public void destroy() {
//do nothing
}
public void init(FilterConfig filterConfig) throws ServletException {
//do nothing
}
}

@ -62,7 +62,7 @@ public class JSONMessageHandler implements MessageBodyWriter<Object>, MessageBod
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream entityStream)
throws IOException, WebApplicationException {
try (InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8")) {
try (InputStreamReader reader = new InputStreamReader(entityStream, UTF_8)) {
return getGson().fromJson(reader, type);
}
}
@ -78,7 +78,6 @@ public class JSONMessageHandler implements MessageBodyWriter<Object>, MessageBod
public void writeTo(Object object, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream entityStream)
throws IOException, WebApplicationException {
try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8)) {
getGson().toJson(object, type, writer);
}

@ -50,7 +50,6 @@ public class ErrorListItem {
this.message = msg;
}
/**
* Description about individual errors occurred
*/

@ -25,15 +25,9 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.api.APIUtil;
import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory;
import org.wso2.carbon.device.application.mgt.extensions.appupload.AppUploadManager;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import static org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory
.ManagerService.APPLICATION_MANAGER;
@Produces({"application/json"})
@Consumes({"application/json"})
public class ApplicationManagementAPIImpl {
@ -49,10 +43,8 @@ public class ApplicationManagementAPIImpl {
@Consumes("application/json")
@Path("applications")
public Response getApplications(@QueryParam("offset") int offset, @QueryParam("limit") int limit,
@QueryParam("q") String searchQuery) {
ApplicationManagementServiceFactory serviceFactory = APIUtil.getApplicationManagementServiceFactory();
ApplicationManager applicationManager = (ApplicationManager) serviceFactory
.getApplicationManagementService(APPLICATION_MANAGER);
@QueryParam("query") String searchQuery) {
ApplicationManager applicationManager = APIUtil.getApplicationManagemer();
try {
if (limit == 0) {
limit = DEFAULT_LIMIT;

@ -16,7 +16,9 @@
~ specific language governing permissions and limitations
~ under the License.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Application Management Webapp</display-name>
<servlet>
<description>JAX-WS/JAX-RS Application Management Endpoint</description>
@ -53,8 +55,20 @@
</context-param>
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>org.wso2.carbon.device.application.mgt.api.APIOriginFilter</filter-class>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,DELETE,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type</param-value>
</init-param>
</filter>
<filter>
@ -94,7 +108,8 @@
</filter-mapping>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -50,10 +50,10 @@ public class Application {
private List<String> tags;
private List<Subscription> subscriptions;
private Platform platform;
private List<Comment> comments;
private Category category;
private Map<String, String> properties;
@ -64,21 +64,49 @@ public class Application {
private Date modifiedAt;
private LifecycleState lifecycleState;
private Payment payment;
private Date lifecycleStateModifiedAt;
private Lifecycle currentLifecycle;
private Date getLifecycleStateModifiedBy;
private List<ApplicationRelease> releases;
private boolean freeApp;
private Visibility visibility;
private String paymentCurrency;
public int getId() {
return id;
}
private Float paymentPrice;
public List<ApplicationRelease> getReleases() {
return releases;
}
public void setReleases(List<ApplicationRelease> releases) {
this.releases = releases;
}
public int getId() {
return id;
public List<Comment> getComments() {
return comments;
}
public void setComments(List<Comment> comments) {
this.comments = comments;
}
public Payment getPayment() {
return payment;
}
public void setPayment(Payment payment) {
this.payment = payment;
}
public Lifecycle getCurrentLifecycle() {
return currentLifecycle;
}
public void setCurrentLifecycle(Lifecycle currentLifecycle) {
this.currentLifecycle = currentLifecycle;
}
public void setId(int id) {
@ -165,14 +193,6 @@ public class Application {
this.tags = tags;
}
public List<Subscription> getSubscriptions() {
return subscriptions;
}
public void setSubscriptions(List<Subscription> subscriptions) {
this.subscriptions = subscriptions;
}
public Platform getPlatform() {
return platform;
}
@ -221,51 +241,11 @@ public class Application {
this.modifiedAt = modifiedAt;
}
public LifecycleState getLifecycleState() {
return lifecycleState;
}
public void setLifecycleState(LifecycleState lifecycleState) {
this.lifecycleState = lifecycleState;
}
public Date getLifecycleStateModifiedAt() {
return lifecycleStateModifiedAt;
}
public void setLifecycleStateModifiedAt(Date lifecycleStateModifiedAt) {
this.lifecycleStateModifiedAt = lifecycleStateModifiedAt;
}
public Date getGetLifecycleStateModifiedBy() {
return getLifecycleStateModifiedBy;
}
public void setGetLifecycleStateModifiedBy(Date getLifecycleStateModifiedBy) {
this.getLifecycleStateModifiedBy = getLifecycleStateModifiedBy;
}
public boolean isFreeApp() {
return freeApp;
}
public void setFreeApp(boolean freeApp) {
this.freeApp = freeApp;
}
public String getPaymentCurrency() {
return paymentCurrency;
}
public void setPaymentCurrency(String paymentCurrency) {
this.paymentCurrency = paymentCurrency;
}
public Float getPaymentPrice() {
return paymentPrice;
public Visibility getVisibility() {
return visibility;
}
public void setPaymentPrice(Float paymentPrice) {
this.paymentPrice = paymentPrice;
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
}

@ -23,7 +23,7 @@ import java.util.Map;
public class ApplicationRelease {
private enum ReleaseChannel {
private enum Channel {
PRODUCTION, ALPHA, BETA
}
@ -35,7 +35,7 @@ public class ApplicationRelease {
private String resource;
private ReleaseChannel releaseChannel;
private Channel releaseChannel;
private String releaseDetails;
@ -83,11 +83,11 @@ public class ApplicationRelease {
this.resource = resource;
}
public ReleaseChannel getReleaseChannel() {
public Channel getReleaseChannel() {
return releaseChannel;
}
public void setReleaseChannel(ReleaseChannel releaseChannel) {
public void setReleaseChannel(Channel releaseChannel) {
this.releaseChannel = releaseChannel;
}

@ -1,65 +0,0 @@
/*
* 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.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
public class ApplicationType {
@Exclude
private int id;
private String name;
private String code;
private String parameters;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getParameters() {
return parameters;
}
public void setParameters(String parameters) {
this.parameters = parameters;
}
}

@ -26,6 +26,7 @@ public class Comment {
private int rating;
//TODO: Pagination, comment ID for child
private Comment parent;
private String createdBy;

@ -31,6 +31,7 @@ public class Filter {
private int offset;
//TODO:
private String filter;
private List<FilterProperty> filterProperties;

@ -18,6 +18,7 @@
*/
package org.wso2.carbon.device.application.mgt.common;
//TODO
public class FilterProperty {
public enum Operator {

@ -0,0 +1,53 @@
/*
* 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.common;
import java.util.Date;
public class Lifecycle {
private LifecycleState lifecycleState;
private Date lifecycleStateModifiedAt;
private Date getLifecycleStateModifiedBy;
public LifecycleState getLifecycleState() {
return lifecycleState;
}
public void setLifecycleState(LifecycleState lifecycleState) {
this.lifecycleState = lifecycleState;
}
public Date getLifecycleStateModifiedAt() {
return lifecycleStateModifiedAt;
}
public void setLifecycleStateModifiedAt(Date lifecycleStateModifiedAt) {
this.lifecycleStateModifiedAt = lifecycleStateModifiedAt;
}
public Date getGetLifecycleStateModifiedBy() {
return getLifecycleStateModifiedBy;
}
public void setGetLifecycleStateModifiedBy(Date getLifecycleStateModifiedBy) {
this.getLifecycleStateModifiedBy = getLifecycleStateModifiedBy;
}
}

@ -0,0 +1,50 @@
/*
* 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.common;
public class Payment {
private boolean freeApp;
private String paymentCurrency;
private Float paymentPrice;
public boolean isFreeApp() {
return freeApp;
}
public void setFreeApp(boolean freeApp) {
this.freeApp = freeApp;
}
public String getPaymentCurrency() {
return paymentCurrency;
}
public void setPaymentCurrency(String paymentCurrency) {
this.paymentCurrency = paymentCurrency;
}
public Float getPaymentPrice() {
return paymentPrice;
}
public void setPaymentPrice(Float paymentPrice) {
this.paymentPrice = paymentPrice;
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
import java.util.List;
import java.util.Map;
public class Platform {
@ -37,9 +38,7 @@ public class Platform {
private List<String> tags;
private String properties;
private List<Application> applications;
private Map<String, String> properties;
public int getId() {
return id;
@ -81,11 +80,11 @@ public class Platform {
this.iconName = iconName;
}
public String getProperties() {
public Map<String, String> getProperties() {
return properties;
}
public void setProperties(String properties) {
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
@ -96,12 +95,4 @@ public class Platform {
public void setTags(List<String> tags) {
this.tags = tags;
}
public List<Application> getApplications() {
return applications;
}
public void setApplications(List<Application> applications) {
this.applications = applications;
}
}

@ -1,52 +0,0 @@
/*
* 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.common;
public class ResourceType {
private String id;
private String name;
private String description;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

@ -22,7 +22,7 @@ import java.util.Date;
public class Subscription {
private ResourceType type;
private Visibility.Type type;
private String value;
@ -40,11 +40,11 @@ public class Subscription {
this.value = value;
}
public ResourceType getType() {
public Visibility.Type getType() {
return type;
}
public void setType(ResourceType type) {
public void setType(Visibility.Type type) {
this.type = type;
}

@ -18,11 +18,10 @@
*/
package org.wso2.carbon.device.application.mgt.common;
import java.util.Date;
//TODO: move to app
public class Visibility {
private ResourceType type;
private Type type;
private String value;
@ -38,11 +37,11 @@ public class Visibility {
this.value = value;
}
public ResourceType getType() {
public Type getType() {
return type;
}
public void setType(ResourceType type) {
public void setType(Type type) {
this.type = type;
}
@ -61,4 +60,37 @@ public class Visibility {
public void setApplicationRelease(ApplicationRelease applicationRelease) {
this.applicationRelease = applicationRelease;
}
public class Type {
private String id;
private String name;
private String description;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
}

@ -1,36 +0,0 @@
/*
* 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.common.services;
import java.util.List;
import java.util.Map;
public abstract class ApplicationManagementExtension {
private Map<String, String> parameters;
public Map<String, String> getParameters() {
return parameters;
}
public void setParameters(Map<String, String> parameters) {
this.parameters = parameters;
}
}

@ -23,7 +23,7 @@ import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
public interface ApplicationManager extends ApplicationManagementService {
public interface ApplicationManager{
void createApplication(Application application) throws ApplicationManagementException;

@ -18,5 +18,5 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
public interface ApplicationReleaseManager extends ApplicationManagementService {
public interface ApplicationReleaseManager{
}

@ -18,5 +18,5 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
public interface CategoryManager extends ApplicationManagementService {
public interface CategoryManager{
}

@ -18,5 +18,5 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
public interface CommentsManager extends ApplicationManagementService {
public interface CommentsManager{
}

@ -18,6 +18,6 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
public interface LifecycleStateManager extends ApplicationManagementService {
public interface LifecycleStateManager {
}

@ -18,5 +18,5 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
public interface PlatformManager extends ApplicationManagementService {
public interface PlatformManager {
}

@ -18,5 +18,5 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
public interface SubscriptionManager extends ApplicationManagementService {
public interface SubscriptionManager {
}

@ -1,22 +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.
*
*/
* 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.common.services;
public interface VisibilityManager extends ApplicationManagementService {
public interface VisibilityManager {
}

@ -1,82 +0,0 @@
/*
* 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.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
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.util.ApplicationManagementUtil;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagerConstants;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.File;
public class ApplicationConfigurationManager {
private final String applicationMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
ApplicationManagerConstants.APPLICATION_CONFIG_XML_FILE;
private static final Log log = LogFactory.getLog(ApplicationConfigurationManager.class);
private ApplicationManagementConfigurations applicationManagerConfiguration;
private static ApplicationConfigurationManager applicationConfigurationManager;
private ApplicationConfigurationManager() {
}
public static ApplicationConfigurationManager getInstance() {
if (applicationConfigurationManager == null) {
applicationConfigurationManager = new ApplicationConfigurationManager();
try {
applicationConfigurationManager.initConfig();
} catch (ApplicationManagementException e) {
log.error(e);
}
}
return applicationConfigurationManager;
}
public synchronized void initConfig() throws ApplicationManagementException {
try {
File appMgtConfig = new File(applicationMgtConfigXMLPath);
Document doc = ApplicationManagementUtil.convertToDocument(appMgtConfig);
/* Un-marshaling Certificate Management configuration */
JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationManagementConfigurations.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
this.applicationManagerConfiguration = (ApplicationManagementConfigurations) unmarshaller.unmarshal(doc);
} catch (Exception e) {
log.error(e);
throw new InvalidConfigurationException("Error occurred while initializing application config", e);
}
}
public ApplicationManagementConfigurations getApplicationManagerConfiguration() {
return applicationManagerConfiguration;
}
}

@ -1,40 +0,0 @@
/*
* 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.config;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "ManagementRepository")
public class ApplicationManagementRepository {
private DataSourceConfig dataSourceConfig;
@XmlElement(name = "DataSourceConfiguration", required = true)
public DataSourceConfig getDataSourceConfig() {
return dataSourceConfig;
}
public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
this.dataSourceConfig = dataSourceConfig;
}
}

@ -0,0 +1,90 @@
/*
* 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.config;
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;
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 static ConfigurationManager configurationManager;
private ConfigurationManager() {
}
public static ConfigurationManager getInstance() {
if (configurationManager == null) {
synchronized (ConfigurationManager.class) {
if (configurationManager == null) {
configurationManager = new ConfigurationManager();
try {
configurationManager.initConfig();
} catch (ApplicationManagementException e) {
log.error(e);
}
}
}
}
return configurationManager;
}
private void initConfig() throws ApplicationManagementException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Configurations.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
this.configuration = (Configurations) unmarshaller.unmarshal(new File(applicationMgtConfigXMLPath));
} catch (Exception e) {
log.error(e);
throw new InvalidConfigurationException("Error occurred while initializing application config: "
+ applicationMgtConfigXMLPath, e);
}
}
public Configurations getConfiguration() {
return configuration;
}
public Extension getExtension(Extension.Name extName) throws InvalidConfigurationException {
for (Extension extension : configuration.getExtensions()) {
if (extension.getName().contentEquals(extName.toString())) {
return extension;
}
}
throw new InvalidConfigurationException("Expecting an extension with name - " + extName + " , but not found!");
}
}

@ -18,33 +18,33 @@
*/
package org.wso2.carbon.device.application.mgt.core.config;
import org.wso2.carbon.device.application.mgt.core.config.extensions.ExtensionsConfig;
import org.wso2.carbon.device.application.mgt.core.config.extensions.Extension;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "ApplicationManagementConfigurations")
public class ApplicationManagementConfigurations {
@XmlRootElement(name = "ApplicationManagementConfiguration")
public class Configurations {
private ApplicationManagementRepository applicationManagerRepository;
private String datasourceName;
private ExtensionsConfig extensionsConfig;
private List<Extension> extensionsConfig;
@XmlElement(name = "ManagementRepository", required = true)
public ApplicationManagementRepository getApplicationManagerRepository() {
return applicationManagerRepository;
@XmlElement(name = "DatasourceName", required = true)
public String getDatasourceName() {
return datasourceName;
}
public void setApplicationManagerRepository(ApplicationManagementRepository applicationManagerRepository) {
this.applicationManagerRepository = applicationManagerRepository;
public void setDatasourceName(String datasourceName) {
this.datasourceName = datasourceName;
}
@XmlElement(name = "ExtensionsConfig", required = false)
public ExtensionsConfig getExtensionsConfig() {
@XmlElement(name = "Extensions", required = false)
public List<Extension> getExtensions() {
return extensionsConfig;
}
public void setExtensionsConfig(ExtensionsConfig extensionsConfig) {
public void setExtensionsConfig(List<Extension> extensionsConfig) {
this.extensionsConfig = extensionsConfig;
}
}

@ -1,40 +0,0 @@
/*
* Copyright (c) 2014, 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.config.datasource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding data source configuration in cdm-config.xml at parsing with JAXB
*/
@XmlRootElement(name = "DataSourceConfiguration")
public class DataSourceConfig {
private JNDILookupDefinition jndiLookupDefinition;
@XmlElement(name = "JndiLookupDefinition", nillable = true)
public JNDILookupDefinition getJndiLookupDefinition() {
return jndiLookupDefinition;
}
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
this.jndiLookupDefinition = jndiLookupDefinition;
}
}

@ -1,79 +0,0 @@
/*
* Copyright (c) 2014, 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.config.datasource;
import javax.xml.bind.annotation.*;
import java.util.List;
/**
* Class for hold JndiLookupDefinition of cdm-config.xml at parsing with JAXB
*/
@XmlRootElement(name = "JndiLookupDefinition")
public class JNDILookupDefinition {
private String jndiName;
private List<JNDIProperty> jndiProperties;
@XmlElement(name = "Name", nillable = false)
public String getJndiName() {
return jndiName;
}
public void setJndiName(String jndiName) {
this.jndiName = jndiName;
}
@XmlElementWrapper(name = "Environment", nillable = false)
@XmlElement(name = "Parameters", nillable = false)
public List<JNDIProperty> getJndiProperties() {
return jndiProperties;
}
public void setJndiProperties(List<JNDIProperty> jndiProperties) {
this.jndiProperties = jndiProperties;
}
@XmlRootElement(name = "Parameters")
public static class JNDIProperty {
private String name;
private String value;
@XmlAttribute(name = "Name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlValue
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}

@ -22,6 +22,7 @@ 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 java.util.List;
import java.util.Map;
@XmlRootElement(name = "Extension")
@ -31,7 +32,7 @@ public class Extension {
private String className;
private Map<String, String> parameters;
private List<Parameter> parameters;
@XmlAttribute(name = "name")
public String getName() {
@ -42,7 +43,7 @@ public class Extension {
this.name = name;
}
@XmlElement(name = "ClassName", nillable = true)
@XmlElement(name = "ClassName", nillable = false)
public String getClassName() {
return className;
}
@ -52,12 +53,35 @@ public class Extension {
}
@XmlElement(name = "Parameters", nillable = true)
@XmlJavaTypeAdapter(ParameterAdapter.class)
public Map<String, String> getParameters() {
public List<Parameter> getParameters() {
return parameters;
}
public void setParameters(Map<String, String> parameters) {
public void setParameters(List<Parameter> parameters) {
this.parameters = parameters;
}
public boolean equals(Object anotherObj){
if (anotherObj instanceof Extension){
Extension anExt = (Extension) anotherObj;
if (anExt.getName().contentEquals(this.getName())){
return true;
}
}
return false;
}
public enum Name {
ApplicationManager,
ApplicationReleaseManager,
ApplicationUploadManager,
CategoryManager,
CommentsManager,
LifecycleStateManager,
PlatformManager,
VisibilityTypeManager,
SubscriptionManager,
VisibilityManager
}
}

@ -1,49 +0,0 @@
/*
* 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.config.extensions;
import javax.xml.bind.annotation.*;
import java.util.List;
@XmlRootElement(name = "Extensions")
public class Extensions {
private List<Extension> extensions;
@XmlElement(name = "Extension")
public List<Extension> getExtensions() {
return extensions;
}
public void setExtensions(List<Extension> extensions) {
this.extensions = extensions;
}
public Extension getExtensionByName(String extensionName) {
if (extensions != null) {
for (Extension extension : extensions) {
if(extension.getName().equals(extensionName)) {
return extension;
}
}
}
return null;
}
}

@ -1,37 +0,0 @@
/*
* 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.config.extensions;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "ExtensionsConfig")
public class ExtensionsConfig {
private Extensions extensions;
@XmlElement(name = "Extensions", nillable = true)
public Extensions getExtensions() {
return extensions;
}
public void setExtensions(Extensions extensions) {
this.extensions = extensions;
}
}

@ -19,23 +19,16 @@
package org.wso2.carbon.device.application.mgt.core.config.extensions;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
@XmlRootElement(name = "Parameter")
public class Parameter {
private String name;
private String value;
Parameter(String name, String value) {
this.name = name;
this.value = value;
}
Parameter(){
}
@XmlAttribute(name = "name")
public String getName() {
return name;

@ -1,50 +0,0 @@
/*
* 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.config.extensions;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class ParameterAdapter extends XmlAdapter<Parameters, Map<String, String>> {
@Override
public Map<String, String> unmarshal(Parameters in) throws Exception {
HashMap<String, String> hashMap = new HashMap<>();
for (Parameter parameter : in.getParameters()) {
hashMap.put(parameter.getName(), parameter.getValue());
}
return hashMap;
}
@Override
public Parameters marshal(Map<String, String> map) throws Exception {
Parameters parameters = new Parameters();
for (Map.Entry<String, String> entry : map.entrySet()) {
parameters.addEntry(new Parameter(entry.getKey(), entry.getValue()));
}
return parameters;
}
}

@ -1,45 +0,0 @@
/*
* 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.config.extensions;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@XmlRootElement(name = "Parameters")
public class Parameters {
private List<Parameter> parameters = new ArrayList<>();;
@XmlElement(name = "Parameter", nillable = true)
public List<Parameter> getParameters() {
return parameters;
}
public void setParameters(List<Parameter> parameters) {
this.parameters = parameters;
}
void addEntry(Parameter parameter) {
parameters.add(parameter);
}
}

@ -18,7 +18,7 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;

@ -21,11 +21,10 @@ package org.wso2.carbon.device.application.mgt.core.dao.common;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.H2ApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.MySQLApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagerConstants;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import javax.sql.DataSource;
@ -37,27 +36,22 @@ import javax.sql.DataSource;
* different data sources, connection acquisition mechanisms as well as different forms of DAO implementations to the
* high-level implementations that require Application management related metadata persistence.
*/
public class ApplicationManagementDAOFactory {
public class DAOFactory {
private static String databaseEngine;
private static final Log log = LogFactory.getLog(ApplicationManagementDAOFactory.class);
private static final Log log = LogFactory.getLog(DAOFactory.class);
public static void init(DataSourceConfig config) {
ConnectionManagerUtil.resolveDataSource(config);
databaseEngine = ConnectionManagerUtil.getDatabaseType();
}
public static void init(DataSource dtSource) {
ConnectionManagerUtil.setDataSource(dtSource);
public static void init(String datasourceName) {
ConnectionManagerUtil.resolveDataSource(datasourceName);
databaseEngine = ConnectionManagerUtil.getDatabaseType();
}
public static ApplicationDAO getApplicationDAO(){
if (databaseEngine != null) {
switch (databaseEngine) {
case ApplicationManagerConstants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_H2:
return new H2ApplicationDAOImpl();
case ApplicationManagerConstants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
return new MySQLApplicationDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);

@ -25,19 +25,15 @@ import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.application.mgt.core.config.datasource.JNDILookupDefinition;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
public class ApplicationManagementDAOUtil {
public class Util {
private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class);
private static final Log log = LogFactory.getLog(Util.class);
public static Application loadApplication(ResultSet rs, ResultSet rsProperties, ResultSet rsTags)
throws SQLException, JSONException {

@ -24,8 +24,8 @@ import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOUtil;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.Connection;
@ -100,7 +100,7 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
ApplicationManagementDAOUtil.cleanupResources(stmt, rs);
Util.cleanupResources(stmt, rs);
}
return count;
}

@ -26,8 +26,8 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.Pagination;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOUtil;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
@ -110,9 +110,9 @@ public class H2ApplicationDAOImpl extends AbstractApplicationDAOImpl {
stmt.setInt(1, rs.getInt("ID"));
ResultSet rsTags = stmt.executeQuery();
applications.add(ApplicationManagementDAOUtil.loadApplication(rs, rsProperties, rsTags));
ApplicationManagementDAOUtil.cleanupResources(null, rsProperties);
ApplicationManagementDAOUtil.cleanupResources(null, rsTags);
applications.add(Util.loadApplication(rs, rsProperties, rsTags));
Util.cleanupResources(null, rsProperties);
Util.cleanupResources(null, rsTags);
length++;
}
@ -128,7 +128,7 @@ public class H2ApplicationDAOImpl extends AbstractApplicationDAOImpl {
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
ApplicationManagementDAOUtil.cleanupResources(stmt, rs);
Util.cleanupResources(stmt, rs);
}
return applicationList;
}

@ -26,8 +26,8 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.Pagination;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOUtil;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
@ -95,7 +95,7 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
rs = stmt.executeQuery();
int length = 0;
sql = "SELECT FOUND_ROWS() AS COUNT;";
sql = "SELECT FOUND_ROWS() AS COUNT;"; //TODO: from which tables????
stmt = conn.prepareStatement(sql);
ResultSet rsCount = stmt.executeQuery();
if (rsCount.next()) {
@ -116,9 +116,9 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
stmt.setInt(1, rs.getInt("ID"));
ResultSet rsTags = stmt.executeQuery();
applications.add(ApplicationManagementDAOUtil.loadApplication(rs, rsProperties, rsTags));
ApplicationManagementDAOUtil.cleanupResources(null, rsProperties);
ApplicationManagementDAOUtil.cleanupResources(null, rsTags);
applications.add(Util.loadApplication(rs, rsProperties, rsTags));
Util.cleanupResources(null, rsProperties);
Util.cleanupResources(null, rsTags);
length++;
}
@ -134,7 +134,7 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
ApplicationManagementDAOUtil.cleanupResources(stmt, rs);
Util.cleanupResources(stmt, rs);
}
return applicationList;
}

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.dao.common;
package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;

@ -1,55 +0,0 @@
/*
* Copyright (c) 2015, 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.exception;
public class KeystoreException extends Exception {
private static final long serialVersionUID = -8935640983869122660L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public KeystoreException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public KeystoreException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public KeystoreException(String msg) {
super(msg);
setErrorMessage(msg);
}
public KeystoreException() {
super();
}
public KeystoreException(Throwable cause) {
super(cause);
}
}

@ -16,17 +16,15 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.services.impl;
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
public class ApplicationManagerImpl implements ApplicationManager {
@ -39,7 +37,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
try {
ConnectionManagerUtil.openConnection();
ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
return applicationDAO.getApplications(filter);
} finally {
ConnectionManagerUtil.closeConnection();

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.services.impl;
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;

@ -1,58 +0,0 @@
/*
* 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.internal;
import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
public class ApplicationManagementDataHolder {
private DeviceManagementProviderService deviceManagementService;
private ApplicationManagementServiceFactory applicationManagementServiceFactory;
private static final ApplicationManagementDataHolder applicationMgtDataHolder = new ApplicationManagementDataHolder();
private ApplicationManagementDataHolder() {
}
public static ApplicationManagementDataHolder getInstance() {
return applicationMgtDataHolder;
}
public DeviceManagementProviderService getDeviceManagementService() {
return deviceManagementService;
}
public void setDeviceManagementService(DeviceManagementProviderService deviceManagementService) {
this.deviceManagementService = deviceManagementService;
}
public ApplicationManagementServiceFactory getApplicationManagementServiceFactory() {
return applicationManagementServiceFactory;
}
public void setApplicationManagementServiceFactory(ApplicationManagementServiceFactory applicationManagementServiceFactory) {
this.applicationManagementServiceFactory = applicationManagementServiceFactory;
}
public static ApplicationManagementDataHolder getApplicationMgtDataHolder() {
return applicationMgtDataHolder;
}
}

@ -1,82 +0,0 @@
/*
* 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.internal;
import org.apache.commons.logging.Log;
import org.osgi.service.component.ComponentContext;
import org.osgi.framework.BundleContext;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManagementService;
import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory;
import org.wso2.carbon.device.application.mgt.core.config.ApplicationConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import javax.naming.NamingException;
/**
* @scr.component name="org.wso2.carbon.application.mgt.service" immediate="true"
* @scr.reference name="org.wso2.carbon.device.manager"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDeviceManagementService"
* unbind="unsetDeviceManagementService"
*/
public class ApplicationManagementServiceComponent {
private static Log log = LogFactory.getLog(ApplicationManagementServiceComponent.class);
protected void activate(ComponentContext componentContext) throws NamingException {
BundleContext bundleContext = componentContext.getBundleContext();
ApplicationManagementServiceFactory serviceFactory = new ApplicationManagementServiceFactory();
ApplicationManagementDataHolder.getInstance().setApplicationManagementServiceFactory(serviceFactory);
bundleContext.registerService(ApplicationManagementServiceFactory.class.getName(), serviceFactory, null);
DataSourceConfig dataSourceConfig = ApplicationConfigurationManager.getInstance()
.getApplicationManagerConfiguration().getApplicationManagerRepository().getDataSourceConfig();
ApplicationManagementDAOFactory.init(dataSourceConfig);
log.info("ApplicationManagement core bundle has been successfully initialized");
if (log.isDebugEnabled()) {
log.debug("ApplicationManagement core bundle has been successfully initialized");
}
}
protected void deactivate(ComponentContext componentContext) {
//do nothing
}
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagementProviderService) {
if (log.isDebugEnabled()) {
log.debug("Setting Application Management OSGI Manager");
}
ApplicationManagementDataHolder.getInstance().setDeviceManagementService(deviceManagementProviderService);
}
protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementProviderService) {
if (log.isDebugEnabled()) {
log.debug("Removing Application Management OSGI Manager");
}
ApplicationManagementDataHolder.getInstance().setDeviceManagementService(null);
}
}

@ -0,0 +1,146 @@
/*
* 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.internal;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
public class DataHolder {
//TODO move the osgi classes here.
private DeviceManagementProviderService deviceManagementService;
private ApplicationManager applicationManager;
private ApplicationReleaseManager releaseManager;
private CategoryManager categoryManager;
private CommentsManager commentsManager;
private LifecycleStateManager lifecycleStateManager;
private PlatformManager platformManager;
private VisibilityTypeManager visibilityTypeManager;
private SubscriptionManager subscriptionManager;
private VisibilityManager visibilityManager;
private ApplicationUploadManager applicationUploadManager;
private static final DataHolder applicationMgtDataHolder = new DataHolder();
private DataHolder() {
}
public static DataHolder getInstance() {
return applicationMgtDataHolder;
}
public DeviceManagementProviderService getDeviceManagementService() {
return deviceManagementService;
}
public void setDeviceManagementService(DeviceManagementProviderService deviceManagementService) {
this.deviceManagementService = deviceManagementService;
}
public static DataHolder getApplicationMgtDataHolder() {
return applicationMgtDataHolder;
}
public ApplicationManager getApplicationManager() {
return applicationManager;
}
public void setApplicationManager(ApplicationManager applicationManager) {
this.applicationManager = applicationManager;
}
public ApplicationReleaseManager getReleaseManager() {
return releaseManager;
}
public void setReleaseManager(ApplicationReleaseManager releaseManager) {
this.releaseManager = releaseManager;
}
public CategoryManager getCategoryManager() {
return categoryManager;
}
public void setCategoryManager(CategoryManager categoryManager) {
this.categoryManager = categoryManager;
}
public CommentsManager getCommentsManager() {
return commentsManager;
}
public void setCommentsManager(CommentsManager commentsManager) {
this.commentsManager = commentsManager;
}
public LifecycleStateManager getLifecycleStateManager() {
return lifecycleStateManager;
}
public void setLifecycleStateManager(LifecycleStateManager lifecycleStateManager) {
this.lifecycleStateManager = lifecycleStateManager;
}
public PlatformManager getPlatformManager() {
return platformManager;
}
public void setPlatformManager(PlatformManager platformManager) {
this.platformManager = platformManager;
}
public VisibilityTypeManager getVisibilityTypeManager() {
return visibilityTypeManager;
}
public void setVisibilityTypeManager(VisibilityTypeManager visibilityTypeManager) {
this.visibilityTypeManager = visibilityTypeManager;
}
public SubscriptionManager getSubscriptionManager() {
return subscriptionManager;
}
public void setSubscriptionManager(SubscriptionManager subscriptionManager) {
this.subscriptionManager = subscriptionManager;
}
public VisibilityManager getVisibilityManager() {
return visibilityManager;
}
public void setVisibilityManager(VisibilityManager visibilityManager) {
this.visibilityManager = visibilityManager;
}
public void setApplicationUploadManager(ApplicationUploadManager applicationUploadManager) {
this.applicationUploadManager = applicationUploadManager;
}
}

@ -0,0 +1,122 @@
/*
* 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.internal;
import org.apache.commons.logging.Log;
import org.osgi.service.component.ComponentContext;
import org.osgi.framework.BundleContext;
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.dao.common.DAOFactory;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import javax.naming.NamingException;
/**
* @scr.component name="org.wso2.carbon.application.mgt.service" immediate="true"
* @scr.reference name="org.wso2.carbon.device.manager"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDeviceManagementService"
* unbind="unsetDeviceManagementService"
*/
public class ServiceComponent {
private static Log log = LogFactory.getLog(ServiceComponent.class);
protected void activate(ComponentContext componentContext) throws NamingException {
BundleContext bundleContext = componentContext.getBundleContext();
try {
String datasourceName = ConfigurationManager.getInstance()
.getConfiguration().getDatasourceName();
DAOFactory.init(datasourceName);
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
DataHolder.getInstance().setApplicationManager(applicationManager);
bundleContext.registerService(ApplicationManager.class.getName(), applicationManager, null);
ApplicationReleaseManager applicationReleaseManager = ApplicationManagementUtil.getApplicationReleaseManagerInstance();
DataHolder.getInstance().setReleaseManager(applicationReleaseManager);
bundleContext.registerService(ApplicationReleaseManager.class.getName(), applicationReleaseManager, null);
CategoryManager categoryManager = ApplicationManagementUtil.getCategoryManagerInstance();
DataHolder.getInstance().setCategoryManager(categoryManager);
bundleContext.registerService(CategoryManager.class.getName(), categoryManager, null);
CommentsManager commentsManager = ApplicationManagementUtil.getCommentsManagerInstance();
DataHolder.getInstance().setCommentsManager(commentsManager);
bundleContext.registerService(CommentsManager.class.getName(), commentsManager, null);
LifecycleStateManager lifecycleStateManager = ApplicationManagementUtil.getLifecycleStateManagerInstance();
DataHolder.getInstance().setLifecycleStateManager(lifecycleStateManager);
bundleContext.registerService(LifecycleStateManager.class.getName(), lifecycleStateManager, null);
PlatformManager platformManager = ApplicationManagementUtil.getPlatformManagerInstance();
DataHolder.getInstance().setPlatformManager(platformManager);
bundleContext.registerService(PlatformManager.class.getName(), platformManager, null);
SubscriptionManager subscriptionManager = ApplicationManagementUtil.getSubscriptionManagerInstance();
DataHolder.getInstance().setSubscriptionManager(subscriptionManager);
bundleContext.registerService(SubscriptionManager.class.getName(), subscriptionManager, null);
VisibilityManager visibilityManager = ApplicationManagementUtil.getVisibilityManagerInstance();
DataHolder.getInstance().setVisibilityManager(visibilityManager);
bundleContext.registerService(VisibilityManager.class.getName(), visibilityManager, null);
VisibilityTypeManager visibilityTypeManager = ApplicationManagementUtil.getVisibilityTypeManagerInstance();
DataHolder.getInstance().setVisibilityTypeManager(visibilityTypeManager);
bundleContext.registerService(VisibilityTypeManager.class.getName(), visibilityTypeManager, null);
ApplicationUploadManager uploadManager = ApplicationManagementUtil.getApplicationUploadManagerInstance();
DataHolder.getInstance().setApplicationUploadManager(uploadManager);
bundleContext.registerService(ApplicationUploadManager.class.getName(), uploadManager, null);
log.info("ApplicationManagement core bundle has been successfully initialized");
if (log.isDebugEnabled()) {
log.debug("ApplicationManagement core bundle has been successfully initialized");
}
} catch (InvalidConfigurationException e) {
log.error("Error while activating Application Management core component. ", e);
}
}
protected void deactivate(ComponentContext componentContext) {
//do nothing
}
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagementProviderService) {
if (log.isDebugEnabled()) {
log.debug("Setting Application Management OSGI Manager");
}
DataHolder.getInstance().setDeviceManagementService(deviceManagementProviderService);
}
protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementProviderService) {
if (log.isDebugEnabled()) {
log.debug("Removing Application Management OSGI Manager");
}
DataHolder.getInstance().setDeviceManagementService(null);
}
}

@ -1,80 +0,0 @@
/*
* 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.services.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.core.config.ApplicationConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.extensions.Extension;
import org.wso2.carbon.device.application.mgt.core.config.extensions.ExtensionsConfig;
public class ApplicationManagementServiceFactory {
private static Log log = LogFactory.getLog(ApplicationManagementServiceFactory.class);
public enum ManagerService {
APPLICATION_MANAGER,
APPLICATION_RELEASE_MANAGER,
CATEGORY_MANAGER,
COMMENTS_MANAGER,
LIFECYCLE_STATE_MANAGER,
PLATFORM_MANAGER,
RESOURCE_TYPE_MANAGER,
SUBSCRIPTION_MANAGER,
VISIBILITY_MANAGER
}
public ApplicationManagementService getApplicationManagementService(ManagerService managerService) {
switch (managerService) {
case APPLICATION_MANAGER:
return new ApplicationManagerImpl();
case APPLICATION_RELEASE_MANAGER:
return new ApplicationReleaseManagerImpl();
default:
return null;
}
}
public ApplicationManagementExtension applicationManagementExtensionsService(String extensionName) {
ApplicationConfigurationManager applicationConfigurationManager = ApplicationConfigurationManager.getInstance();
ExtensionsConfig extensionConfig = applicationConfigurationManager
.getApplicationManagerConfiguration().getExtensionsConfig();
Extension extension = extensionConfig.getExtensions().getExtensionByName(extensionName);
try {
Class<?> theClass = Class.forName(extension.getClassName());
ApplicationManagementExtension appManagementExtension = (ApplicationManagementExtension) theClass.newInstance();
appManagementExtension.setParameters(extension.getParameters());
return appManagementExtension;
} catch (ClassNotFoundException e) {
log.error("Class not Found", e);
} catch (IllegalAccessException e) {
log.error("Illegal Access of Class", e);
} catch (InstantiationException e) {
log.error("Class instantiation exception", e);
}
return null;
}
}

@ -20,43 +20,90 @@ package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.context.PrivilegedCarbonContext;
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.services.impl.ApplicationManagementServiceFactory;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
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 java.lang.reflect.Constructor;
public class ApplicationManagementUtil {
private static Log log = LogFactory.getLog(ApplicationManagementUtil.class);
public static ApplicationManagementServiceFactory getApplicationManagementServiceFactory() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationManagementServiceFactory applicationManagerServiceFactory =
(ApplicationManagementServiceFactory) ctx.getOSGiService(ApplicationManagementServiceFactory.class, null);
if (applicationManagerServiceFactory == null) {
String msg = "Application Management provider service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
public static ApplicationManager getApplicationManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.ApplicationManager);
return getInstance(extension, ApplicationManager.class);
}
public static ApplicationReleaseManager getApplicationReleaseManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.ApplicationReleaseManager);
return getInstance(extension, ApplicationReleaseManager.class);
}
public static CategoryManager getCategoryManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.CategoryManager);
return getInstance(extension, CategoryManager.class);
}
return applicationManagerServiceFactory;
public static CommentsManager getCommentsManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.CommentsManager);
return getInstance(extension, CommentsManager.class);
}
public static LifecycleStateManager getLifecycleStateManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.LifecycleStateManager);
return getInstance(extension, LifecycleStateManager.class);
}
public static PlatformManager getPlatformManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.PlatformManager);
return getInstance(extension, PlatformManager.class);
}
public static Document convertToDocument(File file) throws ApplicationManagementException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
public static VisibilityTypeManager getVisibilityTypeManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.VisibilityTypeManager);
return getInstance(extension, VisibilityTypeManager.class);
}
public static VisibilityManager getVisibilityManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager);
return getInstance(extension, VisibilityManager.class);
}
public static SubscriptionManager getSubscriptionManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.SubscriptionManager);
return getInstance(extension, SubscriptionManager.class);
}
public static ApplicationUploadManager getApplicationUploadManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.ApplicationUploadManager);
return getInstance(extension, ApplicationUploadManager.class);
}
private static <T> T getInstance(Extension extension, Class<T> cls) throws InvalidConfigurationException {
try {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
return docBuilder.parse(file);
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();
}
Constructor<T> constructor = theClass.getConstructor(types);
return constructor.newInstance(paramValues);
} catch (Exception e) {
throw new InvalidConfigurationException("Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document : ", e);
throw new InvalidConfigurationException("Unable to get instance of extension - " + extension.getName()
+ " , for class - " + extension.getClassName(), e);
}
}
}

@ -23,15 +23,11 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.exception.IllegalTransactionStateException;
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.application.mgt.core.config.datasource.JNDILookupDefinition;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.List;
public class ConnectionManagerUtil {
@ -45,10 +41,6 @@ public class ConnectionManagerUtil {
private static ThreadLocal<TxState> currentTxState = new ThreadLocal<>();
private static DataSource dataSource;
public static void setDataSource(DataSource dataSource) {
ConnectionManagerUtil.dataSource = dataSource;
}
public static ThreadLocal<Connection> getCurrentConnection() {
return currentConnection;
}
@ -168,49 +160,17 @@ public class ConnectionManagerUtil {
/**
* Resolve data source from the data source definition.
*
* @param config data source configuration
*
* @param dataSourceName data source name
*/
public static void resolveDataSource(DataSourceConfig config) {
if (config == null) {
throw new RuntimeException(
"Application Management Repository data source configuration " + "is null and " +
"thus, is not initialized"
);
}
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
if (jndiConfig != null) {
if (log.isDebugEnabled()) {
log.debug("Initializing Application Management Repository data source using the JNDI " +
"Lookup Definition");
}
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
jndiConfig.getJndiProperties();
if (jndiPropertyList != null) {
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
jndiProperties.put(prop.getName(), prop.getValue());
}
dataSource = lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
} else {
dataSource = lookupDataSource(jndiConfig.getJndiName(), null);
}
}
}
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
public static void resolveDataSource(String dataSourceName) {
try {
if (jndiProperties == null || jndiProperties.isEmpty()) {
return (DataSource) InitialContext.doLookup(dataSourceName);
}
final InitialContext context = new InitialContext(jndiProperties);
return (DataSource) context.doLookup(dataSourceName);
dataSource = InitialContext.doLookup(dataSourceName);
} catch (Exception e) {
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
}
}
public static String getDatabaseType() {
try {
return dataSource.getConnection().getMetaData().getDatabaseProductName();

@ -18,7 +18,7 @@
*/
package org.wso2.carbon.device.application.mgt.core.util;
public class ApplicationManagerConstants {
public class Constants {
public static final String APPLICATION_CONFIG_XML_FILE = "application-mgt.xml";

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<Parameters>
<Parameter name="UploadPath">repository/resources/mobileapps</Parameter>
</Parameters>
</Extension>
</Extensions>
</ApplicationManagementConfiguration>

@ -1,25 +0,0 @@
/*
* 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.extensions.appupload;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManagementService;
public interface AppUploadManager {
}

@ -18,8 +18,13 @@
*/
package org.wso2.carbon.device.application.mgt.extensions.appupload;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManagementExtension;
public class AppUploadManagerImpl extends ApplicationManagementExtension implements AppUploadManager {
import org.wso2.carbon.device.application.mgt.common.services.ApplicationUploadManager;
public class AppUploadManagerImpl implements ApplicationUploadManager {
public AppUploadManagerImpl(String a, String b){
//do a
}
}

@ -80,7 +80,7 @@
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>org.wso2.carbon.device.application.mgt.extensions</id>
<id>org.wso2.carbon.device.application.mgt.extensions.feature</id>
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
<adviceFile>
<properties>

@ -49,6 +49,11 @@
<artifactId>org.wso2.carbon.device.application.mgt.api.feature</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.extensions.feature</artifactId>
<type>zip</type>
</dependency>
</dependencies>
<build>

@ -2,16 +2,8 @@
<ApplicationManagementConfigurations>
<!-- Application Mgt DB schema -->
<ManagementRepository>
<DataSourceConfiguration>
<JndiLookupDefinition>
<Name>jdbc/APPM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</ManagementRepository>
<DatasourceName>jdbc/APPM_DS</DatasourceName>
<ExtensionsConfig>
<Extensions>
<Extension name="ApplicationUploadExtension">
<ClassName>org.wso2.carbon.device.application.mgt.extensions.appupload.AppUploadManagerImpl</ClassName>
@ -20,6 +12,5 @@
</Parameters>
</Extension>
</Extensions>
</ExtensionsConfig>
</ApplicationManagementConfigurations>
Loading…
Cancel
Save