From a28589878290bbadcd55b739390d41a7cc0de175 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Thu, 30 May 2019 06:31:11 +0000 Subject: [PATCH] Modify the Feature Specification Structure and Modify {deviceType}/features API Related to entgra/product-iots#37 --- .../api/DeviceTypeManagementService.java | 55 +-- .../impl/DeviceTypeManagementServiceImpl.java | 65 ++-- .../impl/DeviceTypeManagementServiceTest.java | 14 +- .../carbon/device/mgt/common/Feature.java | 108 +++++- .../device/mgt/common/FeatureManager.java | 21 + .../device/type/template/config/Feature.java | 65 +++- .../device/type/template/config/Features.java | 18 +- .../device/type/template/config/Filter.java | 76 ++++ .../type/template/config/FormParameters.java | 43 ++- .../type/template/config/Operation.java | 195 +++------- .../template/config/OperationMetadata.java | 120 ++++++ .../device/type/template/config/Params.java | 78 ++++ .../type/template/config/QueryParameters.java | 46 ++- .../type/template/config/UIParameter.java | 134 +++++++ .../type/template/config/UIParameters.java | 48 +++ .../ConfigurationBasedFeatureManager.java | 126 +++++- .../test/resources/device-types/android.xml | 364 ++++++++++++++---- .../resources/device-types/android_sense.xml | 6 +- .../test/resources/device-types/arduino.xml | 16 +- .../device-types/defective-devicetype2.xml | 16 +- .../device-types/defective-devicetype3.xml | 16 +- .../resources/device-types/raspberrypi.xml | 16 +- .../test/resources/device-types/sample.xml | 23 +- .../modules/business-controllers/operation.js | 105 +++-- .../app/pages/cdmf.page.devices/devices.hbs | 77 +++- .../app/pages/cdmf.page.devices/devices.js | 2 + .../cdmf.page.devices/public/js/listing.js | 133 +++++++ .../public/js/dataTables.extended.js | 4 +- .../dataTables.extended.serversidepaging.js | 4 +- .../lib/theme-wso2_1.0/js/theme-wso2.js | 2 +- 30 files changed, 1573 insertions(+), 423 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Filter.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/OperationMetadata.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Params.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameter.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameters.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java index 1b59cfe4fd..132f2c7f5a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java @@ -14,40 +14,41 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * - * - * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. - * - * Entgra (pvt) Ltd. 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 + * Entgra (Pvt) Ltd. 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. + * 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.mgt.jaxrs.service.api; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Info; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.Extension; -import io.swagger.annotations.Tag; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; import io.swagger.annotations.ResponseHeader; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; -import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; @@ -61,9 +62,9 @@ import javax.ws.rs.HeaderParam; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.List; @SwaggerDefinition( info = @Info( @@ -279,8 +280,18 @@ public interface DeviceTypeManagementService { value = "The device type name, such as ios, android, windows or fire-alarm.", required = true) @PathParam("type") - @Size(max = 45) - String type, + @Size(max = 45) String type, + @ApiParam( + name = "featureType", + value = "Type of the feature, such as operation or policy" + ) + @QueryParam("featureType") + String featureType, + @ApiParam( + name = "hidden", + value = "true for hidden operations and false for non hidden operations" + ) + String hidden, @ApiParam( name = "If-Modified-Since", value = "Checks if the requested variant was modified, since the specified date-time.\n" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java index e9129c4c6e..4f58769ebf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java @@ -14,27 +14,28 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * - * - * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. - * - * Entgra (pvt) Ltd. 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 + * Entgra (Pvt) Ltd. 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. - * + * 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.mgt.jaxrs.service.impl; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; @@ -55,6 +56,7 @@ import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.util.ArrayList; import java.util.List; @@ -107,27 +109,42 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ @Override @Path("/{type}/features") public Response getFeatures(@PathParam("type") @Size(max = 45) String type, + @QueryParam("featureType") String featureType, + @QueryParam("hidden") String hidden, @HeaderParam("If-Modified-Since") String ifModifiedSince) { - List features = new ArrayList<>(); + List features; DeviceManagementProviderService dms; try { + if (StringUtils.isEmpty(type)) { + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage("Type cannot be empty.").build()).build(); + } dms = DeviceMgtAPIUtils.getDeviceManagementService(); - FeatureManager fm; - try { - fm = dms.getFeatureManager(type); - } catch (DeviceTypeNotFoundException e) { + FeatureManager fm = dms.getFeatureManager(type); + + if (fm == null) { return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder() - .setMessage("No device type found with name '" + type + "'").build()).build(); + new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " + + "registered with the given type '" + type + "'").build()).build(); } - if (fm != null) { - features = fm.getFeatures(); + + if (StringUtils.isEmpty(hidden)) { + features = fm.getFeatures(featureType); + } else { + features = fm.getFeatures(featureType, Boolean.valueOf(hidden)); } } catch (DeviceManagementException e) { - String msg = "Error occurred while retrieving the list of features of '" + type + "' device type"; + String msg = "Error occurred while retrieving the list of [" + type + "] features with params " + + "{featureType: " + featureType + ", hidden: " + hidden + "}"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } catch (DeviceTypeNotFoundException e) { + String msg = "No device type found with name '" + type + "'"; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder() + .setMessage(msg).build()).build(); } return Response.status(Response.Status.OK).entity(features).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java index fa320b5b5f..f50f8cd812 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java @@ -113,7 +113,7 @@ public class DeviceTypeManagementServiceTest { public void testGetDeviceTypeFeatures() throws Exception { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) .toReturn(this.deviceManagementProviderService); - Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE); + Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, null, "false", MODIFIED_SINCE); Assert.assertNotNull(response, "The response object is null."); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "The response status should be 200."); @@ -126,8 +126,9 @@ public class DeviceTypeManagementServiceTest { FeatureManager featureManager = Mockito.mock(FeatureManager.class); Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn (featureManager); - Mockito.when((featureManager).getFeatures()).thenThrow(new DeviceManagementException()); - Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE); + Mockito.when((featureManager).getFeatures(Mockito.anyString())).thenThrow(new DeviceManagementException()); + Mockito.when((featureManager).getFeatures(Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new DeviceManagementException()); + Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, null, "false", MODIFIED_SINCE); Assert.assertNotNull(response, "The response object is null."); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "The response status should be 500."); @@ -140,11 +141,10 @@ public class DeviceTypeManagementServiceTest { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) .toReturn(this.deviceManagementProviderService); Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn(null); - Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE); + Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, null, "false", MODIFIED_SINCE); Assert.assertNotNull(response, "The response object is null."); - Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), - "The response status should be 200."); - Assert.assertEquals(response.getEntity().toString(), "[]", "The response should be []."); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), + "The response status should be 404."); Mockito.reset(deviceManagementProviderService); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java index cea193877e..0947202898 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java @@ -15,32 +15,92 @@ * specific language governing permissions and limitations * under the License. */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.common; +import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import java.io.Serializable; import java.util.List; import io.swagger.annotations.*; -@ApiModel(value = "Feature", description = "This class carries all information related to a devices enrollment" + - " status.") +@ApiModel( + value = "Feature", + description = "This class carries all information related to a device feature." +) public class Feature implements Serializable { - @ApiModelProperty(name = "id", value = "Feature Id.", required = true ) + @ApiModelProperty( + name = "id", + value = "Feature Id.", + required = true + ) private int id; - @ApiModelProperty(name = "code", value = "The code of the feature. For example the code to lock a device" + - " is DEVICE_LOCK.", required = true ) + + @ApiModelProperty( + name = "code", + value = "The code of the feature. For example the code to lock a device is DEVICE_LOCK.", + required = true + ) private String code; - @ApiModelProperty(name = "name", value = "A name that describes a feature.", required = true ) + + @ApiModelProperty( + name = "name", + value = "A name that describes a feature.", + required = true + ) private String name; - @ApiModelProperty(name = "description", value = "Provides a description of the features..", required = true ) + + @ApiModelProperty( + name = "description", + value = "Provides a description of the features.", + required = true + ) private String description; - @ApiModelProperty(name = "deviceType", value = "Provide the device type for the respective feature. " + - "Features allow you to perform operations on any device type, " + - "such as android, iOS or windows..", required = true ) + + @ApiModelProperty( + name = "type", + value = "Type of the feature.", + required = true + ) + private String type; + + @ApiModelProperty( + name = "hidden", + value = "If the feature is hidden from the UI." + ) + private boolean hidden; + + @ApiModelProperty( + name = "deviceType", + value = "Provide the device type for the respective feature. Features allow you to perform operations " + + "on any device type, such as android, iOS or windows.", + required = true + ) private String deviceType; - @ApiModelProperty(name = "metadataEntries", value = "Properties related to features.", required = true ) + @ApiModelProperty( + name = "metadataEntries", + value = "Properties related to features.", + required = true + ) private List metadataEntries; @XmlElement @@ -96,9 +156,27 @@ public class Feature implements Serializable { this.description = description; } + @XmlAttribute + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public boolean isHidden() { + return hidden; + } + + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + public static class MetadataEntry implements Serializable { private int id; + private String name; private Object value; public int getId() { @@ -109,6 +187,14 @@ public class Feature implements Serializable { this.id = id; } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public Object getValue() { return value; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java index 884311e935..e86cdb77e4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java @@ -14,7 +14,24 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.common; @@ -30,6 +47,10 @@ public interface FeatureManager { List getFeatures() throws DeviceManagementException; + List getFeatures(String type) throws DeviceManagementException; + + List getFeatures(String type, boolean isHidden) throws DeviceManagementException; + boolean removeFeature(String name) throws DeviceManagementException; boolean addSupportedFeaturesToDB() throws DeviceManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Feature.java index 800c4ff71f..b564845194 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Feature.java @@ -14,8 +14,26 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; import javax.xml.bind.annotation.XmlAccessType; @@ -33,41 +51,46 @@ import java.util.List; *

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

- * <complexType name="Feature">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="Description" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="Operation" type="{}Operation"/>
- *       </sequence>
- *       <attribute name="code" type="{http://www.w3.org/2001/XMLSchema}string" />
- *     </restriction>
- *   </complexContent>
- * </complexType>
+ * 
+ *   
+ *     
+ *       
+ *       
+ *       
+ *     
+ *     
+ *     
+ *   
+ * 
  * 
- * - * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Feature", propOrder = { "name", "description", - "operation", "metaData" + "operation", + "metaData" }) public class Feature { @XmlElement(name = "Name", required = true) protected String name; + @XmlElement(name = "Description", required = true) protected String description; - @XmlElement(name = "Operation", required = true) + + @XmlElement(name = "Operation") protected Operation operation; + + @XmlAttribute(name = "type", required = true) + protected String type; + @XmlAttribute(name = "code") protected String code; + @XmlElementWrapper(name = "MetaData") @XmlElement(name = "Property", required = true) - protected List metaData; + private List metaData; /** * Gets the value of the name property. @@ -172,4 +195,12 @@ public class Feature { public void setMetaData(List metaData) { this.metaData = metaData; } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Features.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Features.java index 1904cac3ed..bd2fec5cae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Features.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Features.java @@ -32,15 +32,15 @@ import java.util.List; *

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

- * <complexType name="Features">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="Feature" type="{}Feature"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
  * 
* * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Filter.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Filter.java new file mode 100644 index 0000000000..5262a1ae34 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Filter.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +/** + * Java class for filter complex type. + * + * The following schema fragment specifies the expected content contained within this class. + * + *
+ * 
+ *   
+ *     
+ *       
+ *       
+ *       
+ *     
+ *   
+ * 
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +public class Filter { + @XmlElement(name = "property", required = true) + private String property; + + @XmlElement(name = "value", required = true) + private String value; + + @XmlElement(name = "description", required = true) + private String description; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/FormParameters.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/FormParameters.java index 3cacabb3e4..d0bd140672 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/FormParameters.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/FormParameters.java @@ -14,7 +14,24 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; @@ -27,26 +44,24 @@ import java.util.List; /** - *

Java class for FormParameters complex type. + *

Java class for fromParams complex type. * *

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

- * <complexType name="FormParameters">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="Parameter" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
  * 
- * - * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "FormParameters", propOrder = { +@XmlType(name = "formParams", propOrder = { "parameter" }) public class FormParameters { @@ -56,7 +71,7 @@ public class FormParameters { public List getParameter() { if (parameter == null) { - parameter = new ArrayList(); + parameter = new ArrayList<>(); } return this.parameter; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Operation.java index 06fe5cf1be..74366da00c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Operation.java @@ -14,8 +14,26 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; import javax.xml.bind.annotation.XmlAccessType; @@ -26,164 +44,71 @@ import javax.xml.bind.annotation.XmlType; /** - *

Java class for Operation complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * + * Java class for Operation complex type. + * + * The following schema fragment specifies the expected content contained within this class. + * *

- * <complexType name="Operation">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="QueryParameters" type="{}QueryParameters"/>
- *         <element name="FormParameters" type="{}FormParameters"/>
- *       </sequence>
- *       <attribute name="context" type="{http://www.w3.org/2001/XMLSchema}string" />
- *       <attribute name="method" type="{http://www.w3.org/2001/XMLSchema}string" />
- *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
- *     </restriction>
- *   </complexContent>
- * </complexType>
+ *   
+ *     
+ *       
+ *         
+ *         
+ *       
+ *       
+ *       
+ *     
+ *   
  * 
- * - * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Operation", propOrder = { - "queryParameters", - "formParameters" + "params", + "metadata" }) public class Operation { - @XmlElement(name = "QueryParameters") - protected QueryParameters queryParameters; - @XmlElement(name = "FormParameters") - protected FormParameters formParameters; - @XmlAttribute(name = "context") - protected String context; - @XmlAttribute(name = "method") - protected String method; - @XmlAttribute(name = "type") - protected String type; - - /** - * Gets the value of the Content Type property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getType() { - return type; - } + @XmlElement(name = "params") + private Params params; - /** - * Sets the value of the Content Type property. - * - * @param type - * allowed object is - * {@link String } - * - */ - public void setType(String type) { - this.type = type; - } + @XmlElement(name = "metadata", required = true) + private OperationMetadata metadata; - /** - * Gets the value of the queryParameters property. - * - * @return - * possible object is - * {@link QueryParameters } - * - */ - public QueryParameters getQueryParameters() { - return queryParameters; - } + @XmlAttribute(name = "hidden", required = true) + private boolean hidden; + + @XmlAttribute(name = "icon") + private String icon; - /** - * Sets the value of the queryParameters property. - * - * @param value - * allowed object is - * {@link QueryParameters } - * - */ - public void setQueryParameters(QueryParameters value) { - this.queryParameters = value; + public Params getParams() { + return params; } - /** - * Gets the value of the formParameters property. - * - * @return - * possible object is - * {@link FormParameters } - * - */ - public FormParameters getFormParameters() { - return formParameters; + public void setParams(Params params) { + this.params = params; } - /** - * Sets the value of the formParameters property. - * - * @param value - * allowed object is - * {@link FormParameters } - * - */ - public void setFormParameters(FormParameters value) { - this.formParameters = value; + public OperationMetadata getMetadata() { + return metadata; } - /** - * Gets the value of the context property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getContext() { - return context; + public void setMetadata(OperationMetadata metadata) { + this.metadata = metadata; } - /** - * Sets the value of the context property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setContext(String value) { - this.context = value; + public String getIcon() { + return icon; } - /** - * Gets the value of the method property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getMethod() { - return method; + public void setIcon(String icon) { + this.icon = icon; } - /** - * Sets the value of the method property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setMethod(String value) { - this.method = value; + public boolean isHidden() { + return hidden; } + public void setHidden(boolean hidden) { + this.hidden = hidden; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/OperationMetadata.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/OperationMetadata.java new file mode 100644 index 0000000000..81a4139d8e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/OperationMetadata.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlType; +import java.util.List; + +/** + * Java class for metadata complex type. + * + * The following schema fragment specifies the expected content contained within this class. + * + *
+ * 
+ *   
+ *     
+ *       
+ *       
+ *       
+ *       
+ *       
+ *         
+ *           
+ *             
+ *             
+ *             
+ *           
+ *         
+ *       
+ *     
+ *   
+ * 
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "metadata", propOrder = { + "uri", + "method", + "contentType", + "permission", + "filterList" +}) +public class OperationMetadata { + + @XmlElement(name = "uri", required = true) + private String uri; + + @XmlElement(name = "method", required = true) + private String method; + + @XmlElement(name = "contentType") + private String contentType; + + @XmlElement(name = "permission") + private String permission; + + @XmlElementWrapper(name = "filters") + @XmlElement(name = "filter") + private List filterList; + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + public String getPermission() { + return permission; + } + + public void setPermission(String permission) { + this.permission = permission; + } + + public List getFilterList() { + return filterList; + } + + public void setFilters(List filterList) { + this.filterList = filterList; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Params.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Params.java new file mode 100644 index 0000000000..ad9f5b97bc --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Params.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.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; + +/** + * Java class for params complex type. + * + * The following schema fragment specifies the expected content contained within this class. + * + *
+ *  
+ *    
+ *      
+ *        
+ *        
+ *        
+ *      
+ *    
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "params") +public class Params { + + @XmlElement(name = "queryParams") + private QueryParameters queryParameters; + + @XmlElement(name = "formParams") + private FormParameters formParameters; + + @XmlElement(name = "uiParams") + private UIParameters uiParameters; + + public QueryParameters getQueryParameters() { + return queryParameters; + } + + public void setQueryParameters(QueryParameters queryParameters) { + this.queryParameters = queryParameters; + } + + public FormParameters getFormParameters() { + return formParameters; + } + + public void setFormParameters(FormParameters formParameters) { + this.formParameters = formParameters; + } + + public UIParameters getUiParameters() { + return uiParameters; + } + + public void setUiParameters(UIParameters uiParameters) { + this.uiParameters = uiParameters; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/QueryParameters.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/QueryParameters.java index e79826134e..69c8fd15af 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/QueryParameters.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/QueryParameters.java @@ -14,8 +14,26 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; import javax.xml.bind.annotation.XmlAccessType; @@ -27,26 +45,24 @@ import java.util.List; /** - *

Java class for QueryParameters complex type. + * Java class for queryParams complex type. * - *

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

- * <complexType name="QueryParameters">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="Parameter" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
  * 
- * - * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "QueryParameters", propOrder = { +@XmlType(name = "queryParams", propOrder = { "parameter" }) public class QueryParameters { @@ -56,7 +72,7 @@ public class QueryParameters { public List getParameter() { if (parameter == null) { - parameter = new ArrayList(); + parameter = new ArrayList<>(); } return this.parameter; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameter.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameter.java new file mode 100644 index 0000000000..91db1932b3 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameter.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import java.util.List; + +/** + * Java class for uiParams complex type. + * + * The following schema fragment specifies the expected content contained within this class. + * + *
+ * 
+ *   
+ *     
+ *       
+ *       
+ *       
+ *       
+ *         
+ *           
+ *             
+ *           
+ *         
+ *       
+ *     
+ *     
+ *   
+ * 
+ * 
+ * + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class UIParameter { + + @XmlElement(name = "id", required = true) + protected String id; + + @XmlAttribute(name = "optional", required = true) + private boolean optional; + + @XmlElement(name = "type", required = true) + protected String type; + + @XmlElement(name = "name") + protected String name; + + @XmlElement(name = "label") + private String label; + + @XmlElement(name = "helper") + private String helper; + + @XmlElementWrapper(name = "values") + @XmlElement(name = "value") + protected List value; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getHelper() { + return helper; + } + + public void setHelper(String helper) { + this.helper = helper; + } + + public List getValue() { + return value; + } + + public void setValue(List value) { + this.value = value; + } + + public boolean isOptional() { + return optional; + } + + public void setOptional(boolean optional) { + this.optional = optional; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameters.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameters.java new file mode 100644 index 0000000000..35ad1689e7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/UIParameters.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.config; + +import javax.xml.bind.annotation.XmlElement; +import java.util.List; + +/** + * Java class for uiParams complex type. + * + * The following schema fragment specifies the expected content contained within this class. + * + *
+ * 
+ *   
+ *     
+ *       
+ *     
+ *   
+ * 
+ * 
+ * + */ +public class UIParameters { + + @XmlElement(name = "uiParam") + private List uiParams; + + public List getUiParameterList() { + return this.uiParams; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java index 091123ab7d..a213773eb9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java @@ -16,12 +16,35 @@ * under the License. * */ + +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mgt.extensions.device.type.template.feature; +import org.apache.commons.lang.StringUtils; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Operation; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.OperationMetadata; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Params; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.UIParameter; import java.util.ArrayList; import java.util.HashMap; @@ -37,10 +60,15 @@ public class ConfigurationBasedFeatureManager implements FeatureManager { private List features = new ArrayList<>(); private static final String METHOD = "method"; private static final String URI = "uri"; + private static final String OPERATION_META = "operationMeta"; private static final String CONTENT_TYPE = "contentType"; + private static final String PERMISSION = "permission"; + private static final String ICON = "icon"; + private static final String FILTERS = "filters"; private static final String PATH_PARAMS = "pathParams"; private static final String QUERY_PARAMS = "queryParams"; private static final String FORM_PARAMS = "formParams"; + private static final String UI_PARAMS = "uiParams"; private static final Pattern PATH_PARAM_REGEX = Pattern.compile("\\{(.*?)\\}"); public ConfigurationBasedFeatureManager( @@ -50,6 +78,7 @@ public class ConfigurationBasedFeatureManager implements FeatureManager { deviceFeature.setCode(feature.getCode()); deviceFeature.setName(feature.getName()); deviceFeature.setDescription(feature.getDescription()); + deviceFeature.setType(feature.getType()); Operation operation = feature.getOperation(); List metadataEntries = null; if (feature.getMetaData() != null) { @@ -64,31 +93,53 @@ public class ConfigurationBasedFeatureManager implements FeatureManager { } } if (operation != null) { - Map apiParams = new HashMap<>(); - apiParams.put(METHOD, operation.getMethod().toUpperCase()); - apiParams.put(URI, operation.getContext()); - apiParams.put(CONTENT_TYPE, operation.getType()); + deviceFeature.setHidden(operation.isHidden()); + Map operationMeta = new HashMap<>(); + OperationMetadata metadata = operation.getMetadata(); + List pathParams = new ArrayList<>(); - List queryParams = new ArrayList<>(); - List formParams = new ArrayList<>(); - setPathParams(operation.getContext(), pathParams); - apiParams.put(PATH_PARAMS, pathParams); - if (operation.getQueryParameters() != null) { - queryParams = operation.getQueryParameters().getParameter(); + + if (metadata != null) { + operationMeta.put(METHOD, metadata.getMethod().toUpperCase()); + operationMeta.put(URI, metadata.getUri()); + if (StringUtils.isNotEmpty(metadata.getContentType())) { + operationMeta.put(CONTENT_TYPE, metadata.getContentType()); + } + if (StringUtils.isNotEmpty(metadata.getPermission())) { + operationMeta.put(PERMISSION, metadata.getPermission()); + } + if (metadata.getFilterList() != null && metadata.getFilterList().size() > 0) { + operationMeta.put(FILTERS, metadata.getFilterList()); + } + operationMeta.put(ICON, operation.getIcon()); + setPathParams(metadata.getUri(), pathParams); } - apiParams.put(QUERY_PARAMS, queryParams); - if (operation.getFormParameters() != null) { - formParams = operation.getFormParameters().getParameter(); + operationMeta.put(PATH_PARAMS, pathParams); + + Params params = operation.getParams(); + if (params != null) { + List queryParams = params.getQueryParameters() != null ? + params.getQueryParameters().getParameter() : new ArrayList<>(); + List formParams = params.getFormParameters() != null ? + params.getFormParameters().getParameter() : new ArrayList<>(); + List uiParams = params.getUiParameters() != null ? + params.getUiParameters().getUiParameterList() : new ArrayList<>(); + operationMeta.put(QUERY_PARAMS, queryParams); + operationMeta.put(UI_PARAMS, uiParams); + operationMeta.put(FORM_PARAMS, formParams); } - apiParams.put(FORM_PARAMS, formParams); + if (metadataEntries == null) { metadataEntries = new ArrayList<>(); } Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry(); - metadataEntry.setId(-1); - metadataEntry.setValue(apiParams); + metadataEntry.setId(0); + metadataEntry.setName(OPERATION_META); + metadataEntry.setValue(operationMeta); metadataEntries.add(metadataEntry); deviceFeature.setMetadataEntries(metadataEntries); + } else { + deviceFeature.setHidden(true); } this.features.add(deviceFeature); } @@ -120,6 +171,49 @@ public class ConfigurationBasedFeatureManager implements FeatureManager { return features; } + @Override + public List getFeatures(String type) throws DeviceManagementException { + if (StringUtils.isEmpty(type)) { + return this.getFeatures(); + } + + if (features == null) { + return null; + } else { + List filteredFeatures = new ArrayList<>(); + for (Feature feature : this.getFeatures()) { + if (type.equals(feature.getType())) { + filteredFeatures.add(feature); + } + } + return filteredFeatures; + } + } + + @Override + public List getFeatures(String type, boolean isHidden) throws DeviceManagementException { + if (features == null) { + return null; + } else { + List filteredFeatures = new ArrayList<>(); + if (StringUtils.isEmpty(type)) { + for (Feature feature : this.getFeatures()) { + if (isHidden == feature.isHidden()) { + filteredFeatures.add(feature); + } + } + return filteredFeatures; + } else { + for (Feature feature : this.getFeatures()) { + if (isHidden == feature.isHidden() && type.equals(feature.getType())) { + filteredFeatures.add(feature); + } + } + return filteredFeatures; + } + } + } + @Override public boolean removeFeature(String name) throws DeviceManagementException { return false; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android.xml index 0320698ff4..3a9ce13404 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android.xml @@ -92,256 +92,474 @@ - + Ring Ring the device - + - - test - - + Device Lock Lock the device - + - + Location Request coordinates of device location - + - + Clear Password - Clear current password - + Clear current password (This functionality is only working with profile owners from Android 7.0 API 24 onwards.) + - + Reboot Reboot the device - + - + Upgrade Firmware Upgrade Firmware - + - + Mute Enable mute in the device - + - + Message Send message - + - + Change Lock-code - Change current lock code - + Change current lock code (This functionality is only working with profile owners from Android 7.0 API 24 onwards.) + - + + File Transfer + Transfer file to the device + + + Enterprise Wipe Remove enterprise applications - + - + Wipe Data Factory reset the device - + - + Wifi Setting up wifi configuration - + + Global Proxy + Setting up a network-independent global HTTP proxy on a device. + + Camera Enable or disable camera - + Email Configure email settings - + Device info Request device information - + Application List Request list of current installed applications - + Install App Install App - + Uninstall App Uninstall App - + Blacklist app Blacklist applications - + Encrypt Storage Encrypt storage - + Password Policy Set passcode policy - + Configure VPN Configure VPN settings - + Disallow user to change volume Allow or disallow user to change volume" - + Disallow bluetooth configuration Allow or disallow bluetooth configuration - + Disallow user to change cell broadcast configurations Allow or disallow user to change cell broadcast configurations - + Disallow user to change user credentials Allow or disallow user to change user credentials - + Disallow user to change mobile networks configurations Allow or disallow user to change mobile networks configurations - + Disallow user to change tethering configurations Allow or disallow user to change tethering configurations - + Disallow user to change VPN configurations Allow or disallow user to change VPN configurations - + Disallow user to change WIFI configurations Allow or disallow user to change WIFI configurations - + Disallow user to change app control Allow or disallow user to change app control - + Disallow window creation Allow or disallow window creation - + Disallow user to change app control configurations Allow or disallow user to change app control configurations - + Disallow cross profile copy paste Allow or disallow cross profile copy paste - + Disallow debugging features Allow or disallow debugging features - + Disallow factory reset Allow or disallow factory reset - + Disallow add user Allow or disallow add user - + Disallow install apps Allow or disallow install apps - + Disallow install unknown sources Allow or disallow install unknown sources - + Disallow modify account Allow or disallow modify account - + Disallow mount physical media Allow or disallow mount physical media - + Disallow network reset Allow or disallow network reset - + Disallow outgoing beam Allow or disallow outgoing beam - + Disallow outgoing calls Allow or disallow outgoing calls - + Disallow remove users Allow or disallow remove users - + Disallow safe boot Allow or disallow safe boot - + Disallow share location Allow or disallow share location - + Disallow sms Allow or disallow sms - + Disallow uninstall app Allow or disallow uninstall app - + Disallow unmute mic Allow or disallow unmute mic - + Disallow usb file transfer Allow or disallow usb file transfer - + Disallow parent profile app linking Allow or disallow parent profile app linking - + Disallow ensure verify apps Allow or disallow ensure verify apps - + Disallow auto timing Allow or disallow auto timing - + Remove device owner Remove device owner - + Fetch device logcat Fetch device logcat - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android_sense.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android_sense.xml index fbc58a1115..a5a15b5d1c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android_sense.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/android_sense.xml @@ -19,15 +19,15 @@ --> - + Add Keywords Send keywords to the device - + Add Threshold Send Threshold to the device - + Remove words Remove Threshold from the device diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/arduino.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/arduino.xml index 5b1ed2d468..ad72eadb6c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/arduino.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/arduino.xml @@ -19,13 +19,19 @@ --> - + Control Bulb Control Bulb on Arduino Uno - - - state - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype2.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype2.xml index 0f1baff1c3..258663057f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype2.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype2.xml @@ -21,13 +21,19 @@ - + Control Bulb Control Bulb on Arduino Uno - - - state - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype3.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype3.xml index 063ac8bd53..56f8f2bb56 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype3.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/defective-devicetype3.xml @@ -27,13 +27,19 @@ - + Control Bulb Control Bulb on Arduino Uno - - - state - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/raspberrypi.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/raspberrypi.xml index 5115fafd8e..49c3a49539 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/raspberrypi.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/raspberrypi.xml @@ -19,13 +19,19 @@ --> - + Control Bulb Control Bulb on Raspberrypi - - - state - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/sample.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/sample.xml index 96e6fecc46..2943982aeb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/sample.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/device-types/sample.xml @@ -31,16 +31,23 @@ - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index 1d18e05fe9..be04dda8f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -16,6 +16,24 @@ * under the License. */ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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. + */ + var operationModule = function () { var log = new Log("/app/modules/business-controllers/operation.js"); var utility = require('/app/modules/utility.js').utility; @@ -38,8 +56,9 @@ var operationModule = function () { } privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { - var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types/" + deviceType + "/features"; - var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types/" + + deviceType + "/features?featureType=" + operationType + "&hidden=false"; + return serviceInvokers.XMLHttp.get(url, function (responsePayload) { var features = JSON.parse(responsePayload.responseText); var featureList = []; var feature; @@ -51,20 +70,40 @@ var operationModule = function () { feature["contentType"] = features[i].contentType; feature["deviceType"] = deviceType; feature["params"] = []; - var featuresEntry = utility.getDeviceTypeConfig(deviceType)["deviceType"]["features"]; - if (featuresEntry) { - var featureEntry = featuresEntry[features[i].code]; - if (featureEntry) { - var permissionEntry = featureEntry["permission"]; - if (permissionEntry) { - feature["permission"] = permissionEntry - } - } - } var metaData = features[i].metadataEntries; if (metaData) { for (var j = 0; j < metaData.length; j++) { - feature["params"].push(metaData[j].value); + if (metaData[j].name === "operationMeta") { + var operationMeta = metaData[j].value; + var params = {}; + params["method"] = operationMeta.method; + params["pathParams"] = operationMeta.pathParams; + params["queryParams"] = operationMeta.queryParams; + params["formParams"] = operationMeta.formParams ? operationMeta.formParams : []; + params["uri"] = operationMeta.uri; + params["contentType"] = operationMeta.contentType; + feature["params"].push(params); + feature["permission"] = operationMeta.permission; + if (operationMeta.icon) { + //Check if icon is a path or font + if (operationMeta.icon.indexOf("path:") === 0) { + feature["icon"] = operationMeta.icon.replace("path:", ""); + } else { + feature["iconFont"] = operationMeta.icon; + } + } + if (operationMeta.uiParams && operationMeta.uiParams.length > 0) { + feature["uiParams"] = operationMeta.uiParams; + } + if (operationMeta.filters) { + feature["filters"] = operationMeta.filters; + } + if (operationMeta.ownershipDescription) { + feature["ownershipDescription"] = operationMeta.ownershipDescription; + } + continue; + } + feature["metadata"].push(metaData[j].value); } featureList.push(feature); } @@ -76,39 +115,27 @@ var operationModule = function () { return response; } ); - return featuresList; }; publicMethods.getControlOperations = function (device) { var deviceType = device.type; var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); - var features = utility.getDeviceTypeConfig(deviceType).deviceType.features; for (var op in operations) { - var iconIdentifier = operations[op].operation; - if (features && features[iconIdentifier]) { - var icon = features[iconIdentifier].icon; - //TODO: need improve this check to get feature availability from agent side - var filter = features[iconIdentifier].filter; - if (device && filter && filter.property && device[filter.property] !== filter.value) { - operations[op]["isDisabled"] = true; - operations[op]["disabledText"] = filter.text; - } else { - operations[op]["isDisabled"] = false; - } - if (icon) { - operations[op]["iconFont"] = icon; - } else if (iconPath) { - var iconPath = utility.getOperationIcon(deviceType, iconIdentifier); - operations[op]["icon"] = iconPath; - } - var formParams = features[iconIdentifier].formParams; - if (formParams) { - operations[op]["uiParams"] = formParams; + if (operations.hasOwnProperty(op)) { + operations[op]["isDisabled"] = false; + if (device && operations[op].filters && operations[op].filters.length > 0) { + var filters = operations[op].filters; + for (var filter in filters) { + if (filters.hasOwnProperty(filter)) { + if (device[filters[filter].property] !== filters[filter].value) { + operations[op]["isDisabled"] = true; + operations[op]["disabledText"] = operations[op]["disabledText"] ? + operations[op]["disabledText"] + ", " + filters[filter].description : + filters[filter].description; + } + } + } } - // var icon = utility.getOperationIcon(deviceType, iconIdentifier); - // if (icon) { - // log.error("icon found : " + icon ); - // operations[op]["icon"] = icon; } } return operations; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index 0ff41a245b..cb067c464c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -15,6 +15,24 @@ specific language governing permissions and limitations under the License. }} + +{{! + Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + + Entgra (Pvt) Ltd. 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. +}} {{unit "cdmf.unit.ui.title" pageTitle="Device Management"}} {{unit "cdmf.unit.data-tables-extended"}} @@ -181,7 +199,7 @@ + + +
+ + @@ -508,7 +544,6 @@ -
- +
+ +
+
+ +
@@ -588,7 +655,7 @@ {{#zone "bottomJs"}} + data-portal-url="{{portalUrl}}" data-user-domain="{{userDomain}}" data-api-context="{{apiContext}}" type="text/x-handlebars-template"> {{js "js/listing.js"}} {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index a04b0ab8ac..8976f9f185 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -96,9 +96,11 @@ function onRequest(context) { var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var serverUrl = mdmProps["httpsURL"]; var portalUrl = mdmProps["portalURL"]; + var backendRestEndpoints = mdmProps["backendRestEndpoints"]; var userDomain = context.user.domain; viewModel.serverUrl = serverUrl; viewModel.portalUrl = portalUrl; viewModel.userDomain = userDomain; + viewModel.apiContext = backendRestEndpoints["deviceMgt"]; return viewModel; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index c80e877b68..fbba497e09 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -16,6 +16,24 @@ * under the License. */ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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. + */ + /** * Following function would execute * when a user clicks on the list item @@ -952,6 +970,121 @@ function attachDeviceEvents() { hidePopup(); }); }); + + /** + * Following click function would execute when a user clicks on "Add Operation" link + * on Device Management page in device mgt Console. + */ + $('a.add-operation-link').click(function () { + var operationsRow = $("#device-type-operations-bar"); + if (!operationsRow.hasClass("hidden")) { + operationsRow.addClass("hidden"); + $("#device-type-operations").html(""); + return; + } + var deviceIdentifiers = getSelectedDevices(); + if (deviceIdentifiers.length === 0) { + $(modalPopupContent).html($('#no-device-selected').html()); + $("a#no-device-selected-link").click(function () { + hidePopup(); + }); + showPopup(); + return; + } + + var selectedDeviceType = deviceIdentifiers[0].type; + var deviceList = ""; + var count = 1; + deviceIdentifiers.forEach(function (deviceIdentifier) { + if (selectedDeviceType !== deviceIdentifier.type) { + ++count; + } + deviceList = !deviceList ? deviceIdentifier.id : deviceList + "," + deviceIdentifier.id; + }); + + // If multiple devices of multiple device types selected + if (count > 1) { + $(modalPopupContent).html($('#multiple-device-types-selected').html()); + $("a#multiple-device-types-selected-link").click(function () { + hidePopup(); + }); + showPopup(); + return; + } + var apiContext = $("#device-listing").data("api-context"); + var serviceURL = apiContext + "/device-types/" + selectedDeviceType + "/features?featureType=operation" + + "&hidden=false"; + invokerUtil.get(serviceURL, function (data) { + showOperationBar(JSON.parse(data), selectedDeviceType, deviceList); + }); + }); +} + +function showOperationBar(features, deviceType, deviceList) { + var featureList = []; + var feature; + for (var i = 0; i < features.length; i++) { + feature = {}; + feature.operation = features[i].code; + feature.name = features[i].name; + feature.description = features[i].description; + feature.deviceType = deviceType; + feature.params = []; + var metaData = features[i].metadataEntries; + if (metaData) { + for (var j = 0; j < metaData.length; j++) { + if (metaData[j].name === "operationMeta") { + var operationMeta = metaData[j].value; + var params = {}; + params.method = operationMeta.method; + params.pathParams = operationMeta.pathParams; + params.queryParams = operationMeta.queryParams; + params.formParams = operationMeta.formParams ? operationMeta.formParams : []; + params.uri = operationMeta.uri; + params.contentType = operationMeta.contentType; + feature.params.push(params); + feature.permission = operationMeta.permission; + if (operationMeta.icon) { + if (operationMeta.icon.indexOf("path:") === 0) { + feature.icon = operationMeta.icon.replace("path:", ""); + } else { + feature.iconFont = operationMeta.icon; + } + } + if (operationMeta.uiParams && operationMeta.uiParams.length > 0) { + feature.uiParams = operationMeta.uiParams; + } + continue; + } + feature.metadata.push(metaData[j].value); + } + featureList.push(feature); + } + } + + if (featureList.length > 0) { + var baseUnitPath = context + "/public/cdmf.unit.device.type." + deviceType + ".operation-bar"; + var operationBarScriptSrc = baseUnitPath + "/js/operation-bar.js"; + var operationBarTemplateSrc = baseUnitPath + "/templates/operation-bar.hbs"; + var operationBarCacheKey = deviceType + "-operation-bar"; + + $.template(operationBarCacheKey, operationBarTemplateSrc, function (template) { + var content = template({"controlOperations": featureList, "devices" : deviceList}); + $("#device-type-operations").html(content); + var operationRow = $("#device-type-operations-bar"); + var script = document.createElement("script"); + script.type = "text/javascript"; + script.src = operationBarScriptSrc; + operationRow.prepend(script); + operationRow.removeClass("hidden"); + }); + } else { + $(modalPopupContent).html($('#no-features-available').html()); + $("a#no-features-available-selected-link").click(function () { + hidePopup(); + }); + showPopup(); + } } function removeDevices(deviceIdentifiers) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js index e39e54a930..4d4f7499ec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js @@ -291,7 +291,7 @@ $.fn.datatables_extended = function (settings) { thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); if ($(button).html() == 'Select All') { $(button).html('Deselect All'); - $('.bulk-action-row').removeClass('hidden'); + $('.bulk-action-row:not(.sub-action)').removeClass('hidden'); thisTable.api().rows().every(function () { $(this.node()).addClass(rowSelectedClass); }); @@ -312,7 +312,7 @@ $.fn.datatables_extended = function (settings) { var rowSelectedClass = 'DTTT_selected selected'; $(this).toggleClass(rowSelectedClass); if ($('.table-selectable .DTTT_selected').length > 0) { - $('.bulk-action-row').removeClass('hidden'); + $('.bulk-action-row:not(.sub-action)').removeClass('hidden'); } else { $('.bulk-action-row').addClass('hidden'); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index 4eb499f9f5..aff3ea3942 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -356,7 +356,7 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter if (!$(button).hasClass('disabled')) { if ($(button).html() == 'Select All') { $(button).html('Deselect All'); - $('.bulk-action-row').removeClass('hidden'); + $('.bulk-action-row:not(.sub-action)').removeClass('hidden'); thisTable.api().rows().every(function () { $(this.node()).addClass(rowSelectedClass); }); @@ -378,7 +378,7 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter var rowSelectedClass = 'DTTT_selected selected'; $(this).toggleClass(rowSelectedClass); if ($('.table-selectable .DTTT_selected').length > 0) { - $('.bulk-action-row').removeClass('hidden'); + $('.bulk-action-row:not(.sub-action)').removeClass('hidden'); } else { $('.bulk-action-row').addClass('hidden'); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/js/theme-wso2.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/js/theme-wso2.js index aca2ccd3d0..325948e9dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/js/theme-wso2.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/js/theme-wso2.js @@ -385,7 +385,7 @@ var responsiveTextRatio = 0.2, $('body').on('click', '[data-type=selectable]', function(){ $(this).toggleClass(ROW_SELECTED_CLASS); if ($('.table-selectable .DTTT_selected').length > 0) { - $('.bulk-action-row').removeClass('hidden'); + $('.bulk-action-row:not(.sub-action)').removeClass('hidden'); } else { $('.bulk-action-row').addClass('hidden'); }