From 52e84273d1fed7f649f0b8bc4ec5cbc68a3b0245 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 8 Jun 2016 22:38:49 +0530 Subject: [PATCH] added profile check before publishing apis --- .../webapp/publisher/config/Profiles.java | 57 +++++++++++++++++++ .../config/WebappPublisherConfig.java | 10 ++++ .../APIPublisherLifecycleListener.java | 5 +- .../conf/webapp-publisher-config.xml | 5 +- .../src/main/resources/conf/cdm-config.xml | 4 +- 5 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/Profiles.java diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/Profiles.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/Profiles.java new file mode 100644 index 00000000000..61dfe237f25 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/Profiles.java @@ -0,0 +1,57 @@ + +package org.wso2.carbon.apimgt.webapp.publisher.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import java.util.ArrayList; +import java.util.List; + + +/** + *

Java class for Profiles complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="Profiles">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="Profile" maxOccurs="unbounded" minOccurs="0">
+ *           <simpleType>
+ *             <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *               <enumeration value="default"/>
+ *             </restriction>
+ *           </simpleType>
+ *         </element>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "Profiles", propOrder = { + "profile" +}) +public class Profiles { + + @XmlElement(name = "Profile") + protected List profile; + + /** + * Gets the value of the profile property. + * + */ + public List getProfile() { + if (profile == null) { + profile = new ArrayList(); + } + return this.profile; + } + +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java index 192f91b9061..902d4838db9 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java @@ -40,6 +40,7 @@ public class WebappPublisherConfig { private String host; private boolean isPublished; + private Profiles profiles; private static WebappPublisherConfig config; @@ -71,10 +72,19 @@ public class WebappPublisherConfig { return isPublished; } + @XmlElement(name = "Profiles", required = true) + public Profiles getProfiles() { + return profiles; + } + public void setPublished(boolean published) { isPublished = published; } + public void setProfiles(Profiles profiles) { + this.profiles = profiles; + } + public static void init() throws WebappPublisherConfigurationFailedException { try { File emailSenderConfig = new File(WEBAPP_PUBLISHER_CONFIG_PATH); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java index 042da6b8c27..138fe0ce06e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java @@ -29,6 +29,7 @@ import org.wso2.carbon.apimgt.webapp.publisher.APIConfig; 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.config.WebappPublisherConfig; import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.AnnotationProcessor; @@ -56,8 +57,8 @@ public class APIPublisherLifecycleListener implements LifecycleListener { String profile = System.getProperty(PROPERTY_PROFILE); - if ((profile.equalsIgnoreCase(PROFILE_DT_WORKER) || - profile.equalsIgnoreCase(PROFILE_DEFAULT)) && isManagedApi) { + if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase()) + && isManagedApi) { try { AnnotationProcessor annotationProcessor = new AnnotationProcessor(context); Set annotatedAPIClasses = annotationProcessor. diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/src/main/resources/conf/webapp-publisher-config.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/src/main/resources/conf/webapp-publisher-config.xml index 013bcc3860a..1baf123dad7 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/src/main/resources/conf/webapp-publisher-config.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/src/main/resources/conf/webapp-publisher-config.xml @@ -28,5 +28,8 @@ true - + + + default + \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 449736b1bda..227ec2e5750 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -36,14 +36,14 @@ org.wso2.carbon.policy.mgt - true + false 60000 5 8 20 - true + false 600000 org.wso2.carbon.device.mgt.core.task.impl.DeviceDetailsRetrieverTask