mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #251 from ruwany/master
Making device Type API deployment location configurable
This commit is contained in:
commit
e46ca67aa3
@ -105,6 +105,10 @@
|
||||
<groupId>org.wso2.carbon.governance</groupId>
|
||||
<artifactId>org.wso2.carbon.governance.lcm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@ -30,7 +30,8 @@ import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.AnnotationUtil;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.AnnotationProcessor;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.IOException;
|
||||
@ -51,13 +52,16 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
|
||||
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
|
||||
|
||||
if (isManagedApi) {
|
||||
String profile = System.getProperty(DeviceManagementConstants.Common.PROPERTY_PROFILE);
|
||||
|
||||
if ((profile.equalsIgnoreCase(DeviceManagementConstants.Common.PROFILE_DT_GOVERN) ||
|
||||
profile.equalsIgnoreCase(DeviceManagementConstants.Common.PROFILE_DEFAULT)) && isManagedApi) {
|
||||
try {
|
||||
AnnotationUtil annotationUtil = new AnnotationUtil(context);
|
||||
Set<String> annotatedAPIClasses = annotationUtil.
|
||||
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
|
||||
Set<String> annotatedAPIClasses = annotationProcessor.
|
||||
scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
|
||||
|
||||
List<APIResourceConfiguration> apiDefinitions = annotationUtil.extractAPIInfo(servletContext,
|
||||
List<APIResourceConfiguration> apiDefinitions = annotationProcessor.extractAPIInfo(servletContext,
|
||||
annotatedAPIClasses);
|
||||
|
||||
for (APIResourceConfiguration apiDefinition : apiDefinitions) {
|
||||
|
||||
@ -32,6 +32,8 @@ import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.config.PermissionConfiguration;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.config.PermissionManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.deviceType.DTConfiguration;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.*;
|
||||
@ -47,9 +49,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class AnnotationUtil {
|
||||
public class AnnotationProcessor {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AnnotationUtil.class);
|
||||
private static final Log log = LogFactory.getLog(AnnotationProcessor.class);
|
||||
|
||||
private static final String PACKAGE_ORG_APACHE = "org.apache";
|
||||
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
|
||||
@ -70,7 +72,7 @@ public class AnnotationUtil {
|
||||
private ServletContext servletContext;
|
||||
|
||||
|
||||
public AnnotationUtil(final StandardContext context) {
|
||||
public AnnotationProcessor(final StandardContext context) {
|
||||
this.context = context;
|
||||
servletContext = context.getServletContext();
|
||||
classLoader = servletContext.getClassLoader();
|
||||
@ -175,6 +177,7 @@ public class AnnotationUtil {
|
||||
|
||||
/**
|
||||
* Iterate API annotation and build API Configuration
|
||||
*
|
||||
* @param apiAnno
|
||||
* @return
|
||||
* @throws Throwable
|
||||
@ -204,6 +207,7 @@ public class AnnotationUtil {
|
||||
|
||||
/**
|
||||
* Get Resources for each API
|
||||
*
|
||||
* @param resourceRootContext
|
||||
* @param apiRootContext
|
||||
* @param annotatedMethods
|
||||
@ -221,8 +225,11 @@ public class AnnotationUtil {
|
||||
APIResource resource = new APIResource();
|
||||
resource.setUriTemplate(makeContextURLReady(apiRootContext + subCtx));
|
||||
|
||||
String serverIP = System.getProperty(SERVER_HOST);
|
||||
String httpServerPort = System.getProperty(HTTP_PORT);
|
||||
DTConfiguration deviceTypeConfig = DeviceConfigurationManager.getInstance().
|
||||
getDeviceManagementConfig().getDTDeploymentConfiguration();
|
||||
|
||||
String serverIP = deviceTypeConfig.getDtHostAddress();
|
||||
String httpServerPort = deviceTypeConfig.getDtHostPort();
|
||||
|
||||
resource.setUri(PROTOCOL_HTTP + "://" + serverIP + ":" + httpServerPort + makeContextURLReady(
|
||||
resourceRootContext) + makeContextURLReady(subCtx));
|
||||
@ -266,6 +273,7 @@ public class AnnotationUtil {
|
||||
|
||||
/**
|
||||
* Read Method annotations indicating HTTP Methods
|
||||
*
|
||||
* @param resource
|
||||
* @param annotation
|
||||
*/
|
||||
@ -289,6 +297,7 @@ public class AnnotationUtil {
|
||||
|
||||
/**
|
||||
* Append '/' to the context and make it URL ready
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
@ -28,6 +28,9 @@ public final class DeviceManagementConstants {
|
||||
|
||||
public static final String PROPERTY_SETUP = "setup";
|
||||
public static final String DEFAULT_LICENSE_CONFIG_XML_NAME = "license-config.xml";
|
||||
public static final String PROPERTY_PROFILE = "profile";
|
||||
public static final String PROFILE_DT_GOVERN = "deviceTypeGovern";
|
||||
public static final String PROFILE_DEFAULT = "default";
|
||||
}
|
||||
|
||||
public static final class AppManagement {
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.config.deviceType.DTConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration;
|
||||
@ -37,6 +38,7 @@ public final class DeviceManagementConfig {
|
||||
private IdentityConfigurations identityConfigurations;
|
||||
private PolicyConfiguration policyConfiguration;
|
||||
//private List<String> pushNotificationProviders;
|
||||
private DTConfiguration dTDepyloymentConfiguration;
|
||||
|
||||
@XmlElement(name = "ManagementRepository", required = true)
|
||||
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
|
||||
@ -75,6 +77,15 @@ public final class DeviceManagementConfig {
|
||||
this.taskConfiguration = taskConfiguration;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DTDeploymentConfiguration", required = true)
|
||||
public DTConfiguration getDTDeploymentConfiguration() {
|
||||
return dTDepyloymentConfiguration;
|
||||
}
|
||||
|
||||
public void setDTDeploymentConfiguration(DTConfiguration dTDeploymentConfiguration) {
|
||||
this.dTDepyloymentConfiguration = dTDeploymentConfiguration;
|
||||
}
|
||||
|
||||
// @XmlElementWrapper(name = "PushNotificationProviders", required = true)
|
||||
// @XmlElement(name = "Provider", required = true)
|
||||
// public List<String> getPushNotificationProviders() {
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This class will read the configurations related to task. This task will be responsible for adding the operations.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config.deviceType;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DTDepyloymentConfiguration")
|
||||
public class DTConfiguration {
|
||||
|
||||
private String dtHostAddress;
|
||||
private String dtHostPort;
|
||||
|
||||
@XmlElement(name = "DTHostAddress", required = true)
|
||||
public String getDtHostAddress() {
|
||||
return dtHostAddress;
|
||||
}
|
||||
|
||||
public void setDtHostAddress(String dtHostAddress) {
|
||||
this.dtHostAddress = dtHostAddress;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DTHostPort", required = true)
|
||||
public String getDtHostPort() {
|
||||
return dtHostPort;
|
||||
}
|
||||
|
||||
public void setDtHostPort(String dtHostPort) {
|
||||
this.dtHostPort = dtHostPort;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -90,6 +90,10 @@
|
||||
<groupId>commons-lang.wso2</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -110,6 +114,7 @@
|
||||
<Import-Package>
|
||||
org.wso2.carbon.governance.api.*,
|
||||
javax.xml.namespace;resolution:=optional,
|
||||
org.wso2.carbon.device.mgt.core.*,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.device.mgt.common,
|
||||
org.wso2.carbon.device.mgt.common.license.mgt,
|
||||
|
||||
@ -24,9 +24,10 @@ import org.apache.catalina.core.StandardContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.GenericFeatureManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.util.AnnotationUtil;
|
||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.util.AnnotationProcessor;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.IOException;
|
||||
@ -51,11 +52,15 @@ public class FeatureManagementLifecycleListener implements LifecycleListener {
|
||||
ServletContext servletContext = context.getServletContext();
|
||||
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
|
||||
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
|
||||
if (isManagedApi) {
|
||||
|
||||
String profile = System.getProperty(DeviceManagementConstants.Common.PROPERTY_PROFILE);
|
||||
|
||||
if ((profile.equalsIgnoreCase(DeviceManagementConstants.Common.PROFILE_DT_GOVERN) ||
|
||||
profile.equalsIgnoreCase(DeviceManagementConstants.Common.PROFILE_DEFAULT)) && isManagedApi) {
|
||||
try {
|
||||
AnnotationUtil annotationUtil = new AnnotationUtil(context);
|
||||
Set<String> annotatedAPIClasses = annotationUtil.scanStandardContext(DeviceType.class.getName());
|
||||
Map<String, List<Feature>> features = annotationUtil.extractFeatures(annotatedAPIClasses);
|
||||
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
|
||||
Set<String> annotatedAPIClasses = annotationProcessor.scanStandardContext(DeviceType.class.getName());
|
||||
Map<String, List<Feature>> features = annotationProcessor.extractFeatures(annotatedAPIClasses);
|
||||
if (features != null && !features.isEmpty()) {
|
||||
GenericFeatureManager.getInstance().addFeatures(features);
|
||||
}
|
||||
|
||||
@ -55,9 +55,9 @@ import java.util.Set;
|
||||
/**
|
||||
* This has the utility function to extract feature information.
|
||||
*/
|
||||
public class AnnotationUtil {
|
||||
public class AnnotationProcessor {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AnnotationUtil.class);
|
||||
private static final Log log = LogFactory.getLog(AnnotationProcessor.class);
|
||||
|
||||
private static final String PACKAGE_ORG_APACHE = "org.apache";
|
||||
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
|
||||
@ -71,7 +71,7 @@ public class AnnotationUtil {
|
||||
private ServletContext servletContext;
|
||||
|
||||
|
||||
public AnnotationUtil(final StandardContext context) {
|
||||
public AnnotationProcessor(final StandardContext context) {
|
||||
servletContext = context.getServletContext();
|
||||
classLoader = servletContext.getClassLoader();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user