mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
merged with IoTS-1.0.0 branch
This commit is contained in:
commit
33bb9b5a14
@ -22,13 +22,13 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Annotations</name>
|
||||
<description>WSO2 Carbon - API Management Custom Annotation Module</description>
|
||||
|
||||
@ -21,12 +21,12 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<artifactId>org.wso2.carbon.apimgt.application.extension.api</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>WSO2 Carbon - API Application Management API</name>
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.apimgt.application.extension.api.filter;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* 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
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* 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
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* 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
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* 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
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
@ -22,12 +22,12 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Application Management</name>
|
||||
|
||||
@ -22,13 +22,13 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Webapp Publisher</name>
|
||||
<description>WSO2 Carbon - API Management Webapp Publisher</description>
|
||||
|
||||
@ -64,6 +64,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
||||
CommonUtil.getRootSystemRegistry(tenantId));
|
||||
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(api.getApiOwner());
|
||||
MultitenantUtils.getTenantDomain(api.getApiOwner());
|
||||
processHttpVerbs(api);
|
||||
if (provider != null) {
|
||||
if (provider.isDuplicateContextTemplate(api.getContext())) {
|
||||
throw new APIManagementException(
|
||||
@ -87,8 +88,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
||||
provider.updateAPI(api);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("An API already exists with the name '" + api.getId().getApiName() +
|
||||
"', context '" + api.getContext() + "' and version '"
|
||||
+ api.getId().getVersion() + "'. Thus, the API config is updated");
|
||||
"', context '" + api.getContext() + "' and version '"
|
||||
+ api.getId().getVersion() + "'. Thus, the API config is updated");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -172,6 +173,23 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
||||
return swaggerDefinition.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes the httpVerb string attribute is not existing in
|
||||
* the list of httpVerbs attribute of uriTemplate. In such cases when creating the api in the
|
||||
* synapse configuration, it doesn't have http methods correctly assigned for the resources.
|
||||
* Therefore this method takes care of such inconsistency issue.
|
||||
*
|
||||
* @param api The actual API model object
|
||||
*/
|
||||
private void processHttpVerbs(API api) {
|
||||
for (URITemplate uriTemplate : api.getUriTemplates()) {
|
||||
String httpVerbString = uriTemplate.getHTTPVerb();
|
||||
if (httpVerbString != null && !httpVerbString.isEmpty()) {
|
||||
uriTemplate.setHttpVerbs(httpVerbString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAPI(APIIdentifier id) throws APIManagementException {
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
@ -1,4 +1,20 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.apimgt.webapp.publisher.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
|
||||
@ -22,13 +22,13 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - API Management Extensions Component</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -42,8 +43,10 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
||||
for (EnrollmentCertificate enrollmentCertificate : enrollmentCertificates) {
|
||||
certificate = new org.wso2.carbon.certificate.mgt.core.bean.Certificate();
|
||||
certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
certificate.setSerial(enrollmentCertificate.getSerial());
|
||||
certificate.setCertificate(certificateService.pemToX509Certificate(enrollmentCertificate.getPem()));
|
||||
X509Certificate x509Certificate = certificateService
|
||||
.pemToX509Certificate(enrollmentCertificate.getPem());
|
||||
certificate.setSerial(x509Certificate.getSerialNumber().toString());
|
||||
certificate.setCertificate(x509Certificate);
|
||||
certificates.add(certificate);
|
||||
}
|
||||
certificateService.saveCertificate(certificates);
|
||||
|
||||
@ -21,13 +21,13 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Certificate Management Core</name>
|
||||
<description>WSO2 Carbon - Certificate Management Core</description>
|
||||
|
||||
@ -22,14 +22,14 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - Certificate Management Component</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceGroupList extends BasePaginatedResult {
|
||||
|
||||
@ApiModelProperty(value = "List of device groups returned")
|
||||
@JsonProperty("groups")
|
||||
private List<?> deviceGroups = new ArrayList<>();
|
||||
|
||||
public List<?> getList() {
|
||||
return deviceGroups;
|
||||
}
|
||||
|
||||
public void setList(List<?> deviceGroups) {
|
||||
this.deviceGroups = deviceGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" groups: [").append(deviceGroups).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* This class holds Device Group user name and assigned roles of user for particular group. Exposed to external access.
|
||||
*/
|
||||
@ApiModel(value = "DeviceGroupShare", description = "This class carries roles assigned to a user of a managed device group.")
|
||||
public class DeviceGroupShare implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1998141711L;
|
||||
|
||||
@ApiModelProperty(name = "username", value = "Username of the user.", required = true)
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(name = "roles", value = "List of roles assigned to user from the group.")
|
||||
private List<String> groupRoles;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public List<String> getGroupRoles() {
|
||||
return groupRoles;
|
||||
}
|
||||
|
||||
public void setGroupRoles(List<String> groupRoles) {
|
||||
this.groupRoles = groupRoles;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceGroupUsersList extends BasePaginatedResult {
|
||||
|
||||
@ApiModelProperty(value = "List of device group users returned")
|
||||
@JsonProperty("users")
|
||||
private List<GroupUser> users = new ArrayList<>();
|
||||
|
||||
public List<GroupUser> getList() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setList(List<GroupUser> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" users: [").append(users).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -128,6 +128,12 @@ public interface DeviceManagementService {
|
||||
@QueryParam("status")
|
||||
@Size(max = 45)
|
||||
String status,
|
||||
@ApiParam(
|
||||
name = "groupId",
|
||||
value = "Id of the group which device belongs",
|
||||
required = false)
|
||||
@QueryParam("groupId")
|
||||
int groupId,
|
||||
@ApiParam(
|
||||
name = "since",
|
||||
value = "Checks if the requested variant was created since the specified date-time.\n" +
|
||||
@ -647,7 +653,14 @@ public interface DeviceManagementService {
|
||||
required = false,
|
||||
defaultValue = "5")
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
int limit,
|
||||
@ApiParam(
|
||||
name = "owner",
|
||||
value = "Provides the owner of the required device.",
|
||||
required = true,
|
||||
defaultValue = "")
|
||||
@QueryParam("owner")
|
||||
String owner);
|
||||
|
||||
@GET
|
||||
@Path("/{type}/{id}/effective-policy")
|
||||
|
||||
@ -0,0 +1,726 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
||||
|
||||
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.ResponseHeader;
|
||||
import org.apache.axis2.transport.http.HTTPConstants;
|
||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupShare;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupUsersList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Device group related REST-API. This can be used to manipulated device group related details.
|
||||
*/
|
||||
@API(name = "GroupManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"device_management"})
|
||||
|
||||
@Path("/groups")
|
||||
@Api(value = "Device Group Management", description = "This API carries all device group management related operations " +
|
||||
"such as get all the available groups, etc.")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface GroupManagementService {
|
||||
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "Get the list of groups belongs to current user.",
|
||||
notes = "Returns all permitted groups enrolled with the system.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.",
|
||||
response = DeviceGroupList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the groups list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
|
||||
Response getGroups(@ApiParam(
|
||||
name = "name",
|
||||
value = "Name of the group.")
|
||||
@QueryParam("name") String name,
|
||||
@ApiParam(
|
||||
name = "owner",
|
||||
value = "Owner of the group.")
|
||||
@QueryParam("owner") String owner,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.")
|
||||
@QueryParam("offset") int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.")
|
||||
@QueryParam("limit") int limit);
|
||||
|
||||
@Path("/count")
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "Get the count of groups belongs to current user.",
|
||||
notes = "Returns count of all permitted groups enrolled with the system.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.",
|
||||
response = DeviceGroupList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the group count.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
|
||||
Response getGroupCount();
|
||||
|
||||
@POST
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_POST,
|
||||
value = "Add new device group to the system.",
|
||||
notes = "Add device group with current user as the owner.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Device group has successfully been created",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The URL of the added group."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests.")
|
||||
}
|
||||
),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 401,
|
||||
message = "Unauthorized. \n Current logged in user is not authorized to add device groups.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding a new device group.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "Add Group", permission = "/device-mgt/groups/add")
|
||||
Response createGroup(@ApiParam(
|
||||
name = "group",
|
||||
value = "Group object with data.",
|
||||
required = true)
|
||||
@Valid DeviceGroup group);
|
||||
|
||||
@Path("/id/{groupId}")
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "View group specified.",
|
||||
notes = "Returns details of group enrolled with the system.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group.",
|
||||
response = DeviceGroup.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the group details.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
|
||||
Response getGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group to view.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId);
|
||||
|
||||
@Path("/id/{groupId}")
|
||||
@PUT
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_PUT,
|
||||
value = "Update a group.",
|
||||
notes = "If you wish to make changes to an existing group, that can be done by updating the group using " +
|
||||
"this resource.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Group has been updated successfully.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body."),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while updating the group.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "Update Group", permission = "/device-mgt/groups/update")
|
||||
Response updateGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group to be updated.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId,
|
||||
@ApiParam(
|
||||
name = "group",
|
||||
value = "Group object with data.",
|
||||
required = true)
|
||||
@Valid DeviceGroup deviceGroup);
|
||||
|
||||
@Path("/id/{groupId}")
|
||||
@DELETE
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_DELETE,
|
||||
value = "Delete a group.",
|
||||
notes = "If you wish to remove an existing group, that can be done by updating the group using " +
|
||||
"this resource.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Group has been deleted successfully.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body."),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while removing the group.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "Remove Group", permission = "/device-mgt/groups/remove")
|
||||
Response deleteGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group to be deleted.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId);
|
||||
|
||||
@Path("/id/{groupId}/share")
|
||||
@POST
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_POST,
|
||||
value = "Manage group sharing with a user.",
|
||||
notes = "If you wish to share /un share an existing group with a user under defined sharing roles, " +
|
||||
"that can be done using this resource.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Sharing has been updated successfully.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body."),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while sharing the group.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "Share Group", permission = "/device-mgt/groups/share")
|
||||
Response manageGroupSharing(@ApiParam(
|
||||
name = "groupName",
|
||||
value = "Name of the group to be shared or unshared.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId,
|
||||
@ApiParam(
|
||||
name = "deviceGroupShare",
|
||||
value = "User name and the assigned roles for the share.",
|
||||
required = true)
|
||||
@Valid DeviceGroupShare deviceGroupShare);
|
||||
|
||||
@Path("/id/{groupId}/users")
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "View list of users of a device group.",
|
||||
notes = "Returns details of users which particular group has been shared with.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.",
|
||||
response = DeviceGroupUsersList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the users.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View users", permission = "/device-mgt/groups/users/view")
|
||||
Response getUsersOfGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId);
|
||||
|
||||
@Path("/id/{groupId}/roles")
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "View list of roles of a device group.",
|
||||
notes = "Returns details of roles which particular group has been shared with.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.",
|
||||
response = DeviceGroupUsersList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the roles.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View roles", permission = "/device-mgt/groups/roles/view")
|
||||
Response getRolesOfGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId,
|
||||
@ApiParam(
|
||||
name = "userName",
|
||||
value = "User name of the current user.",
|
||||
required = false)
|
||||
@QueryParam("userName") String userName);
|
||||
|
||||
@Path("/id/{groupId}/devices")
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "View list of devices in the device group.",
|
||||
notes = "Returns list of devices in the device group.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the devices.",
|
||||
response = DeviceList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the devices.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View devices", permission = "/device-mgt/groups/devices/view")
|
||||
Response getDevicesOfGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.")
|
||||
@QueryParam("offset") int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.")
|
||||
@QueryParam("limit") int limit);
|
||||
|
||||
@Path("/id/{groupId}/devices/count")
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "View list of device count in the device group.",
|
||||
notes = "Returns device count in the device group.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device count.",
|
||||
response = DeviceList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching device count.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View devices", permission = "/device-mgt/groups/devices/view")
|
||||
Response getDeviceCountOfGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId);
|
||||
|
||||
@Path("/id/{groupId}/devices")
|
||||
@POST
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_POST,
|
||||
value = "Add devices to group.",
|
||||
notes = "Add existing devices to the device group.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully add devices to the group.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while adding devices to the group.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "Add devices", permission = "/device-mgt/groups/devices/add")
|
||||
Response addDevicesToGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId,
|
||||
@ApiParam(
|
||||
name = "deviceIdentifiers",
|
||||
value = "Device identifiers of the devices which needed be added.",
|
||||
required = true)
|
||||
@Valid List<DeviceIdentifier> deviceIdentifiers);
|
||||
|
||||
@Path("/id/{groupId}/devices")
|
||||
@DELETE
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_DELETE,
|
||||
value = "Remove devices from group.",
|
||||
notes = "Remove existing devices from the device group.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully removed devices from the group.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while removing devices from the group.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "Remove devices", permission = "/device-mgt/groups/devices/remove")
|
||||
Response removeDevicesFromGroup(@ApiParam(
|
||||
name = "groupId",
|
||||
value = "ID of the group.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId,
|
||||
@ApiParam(
|
||||
name = "deviceIdentifiers",
|
||||
value = "Device identifiers of the devices which needed to be removed.",
|
||||
required = true)
|
||||
@Valid List<DeviceIdentifier> deviceIdentifiers);
|
||||
|
||||
}
|
||||
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
||||
|
||||
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.ResponseHeader;
|
||||
import org.apache.axis2.transport.http.HTTPConstants;
|
||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@API(name = "GroupManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/groups", tags = {"device_management"})
|
||||
|
||||
@Path("/admin/groups")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Api(value = "Group Management Administrative Service", description = "This an API intended to be used by " +
|
||||
"'internal' components to log in as an admin user and do a selected number of operations. " +
|
||||
"Further, this is strictly restricted to admin users only ")
|
||||
public interface GroupManagementAdminService {
|
||||
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "Get the list of groups.",
|
||||
notes = "Returns all groups enrolled with the system.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.",
|
||||
response = DeviceGroupList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the groups list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View Groups", permission = "/device-mgt/admin/groups/view")
|
||||
Response getGroups(@ApiParam(
|
||||
name = "name",
|
||||
value = "Name of the group.")
|
||||
@QueryParam("name") String name,
|
||||
@ApiParam(
|
||||
name = "owner",
|
||||
value = "Owner of the group.")
|
||||
@QueryParam("owner") String owner,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.")
|
||||
@QueryParam("offset") int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.")
|
||||
@QueryParam("limit") int limit);
|
||||
|
||||
@Path("/count")
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "Get the count of groups belongs to current user.",
|
||||
notes = "Returns count of all permitted groups enrolled with the system.",
|
||||
tags = "Device Group Management")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.",
|
||||
response = DeviceGroupList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||
"the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "No groups found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the group count.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(name = "View Groups", permission = "/device-mgt/admin/groups/view")
|
||||
Response getGroupCount();
|
||||
|
||||
}
|
||||
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
@ -72,6 +71,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
@QueryParam("user") String user,
|
||||
@QueryParam("ownership") String ownership,
|
||||
@QueryParam("status") String status,
|
||||
@QueryParam("groupId") int groupId,
|
||||
@QueryParam("since") String since,
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||
@QueryParam("offset") int offset,
|
||||
@ -108,6 +108,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
RequestValidationUtil.validateStatus(status);
|
||||
request.setStatus(status);
|
||||
}
|
||||
if (groupId != 0 ) {
|
||||
request.setGroupId(groupId);
|
||||
}
|
||||
|
||||
// this is the user who initiates the request
|
||||
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
@ -380,10 +383,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
@PathParam("id") @Size(max = 45) String id,
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit) {
|
||||
@QueryParam("limit") int limit,
|
||||
@QueryParam("owner") String owner) {
|
||||
OperationList operationsList = new OperationList();
|
||||
RequestValidationUtil.validateOwnerParameter(owner);
|
||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
||||
PaginationRequest request = new PaginationRequest(offset, limit);
|
||||
request.setOwner(owner);
|
||||
PaginationResult result;
|
||||
DeviceManagementProviderService dms;
|
||||
try {
|
||||
|
||||
@ -0,0 +1,292 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.user.core.UserStoreException;
|
||||
import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupManagementServiceImpl implements GroupManagementService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GroupManagementServiceImpl.class);
|
||||
|
||||
private static final String DEFAULT_ADMIN_ROLE = "admin";
|
||||
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
|
||||
"/permission/device-mgt/user/groups"};
|
||||
private static final String EMPTY_RESULT = "EMPTY";
|
||||
|
||||
@Override
|
||||
public Response getGroups(String name, String owner, int offset, int limit) {
|
||||
try {
|
||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
||||
String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
GroupPaginationRequest request = new GroupPaginationRequest(offset, limit);
|
||||
request.setGroupName(name);
|
||||
request.setOwner(owner);
|
||||
PaginationResult deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||
.getGroups(currentUser, request);
|
||||
if (deviceGroupsResult.getData() != null && deviceGroupsResult.getRecordsTotal() > 0) {
|
||||
DeviceGroupList deviceGroupList = new DeviceGroupList();
|
||||
deviceGroupList.setList(deviceGroupsResult.getData());
|
||||
deviceGroupList.setCount(deviceGroupsResult.getRecordsTotal());
|
||||
return Response.status(Response.Status.OK).entity(deviceGroupList).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String error = "Error occurred while getting the groups.";
|
||||
log.error(error, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getGroupCount() {
|
||||
try {
|
||||
String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount(currentUser);
|
||||
return Response.status(Response.Status.OK).entity(count).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while retrieving group count.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response createGroup(DeviceGroup group) {
|
||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
if (group == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
group.setOwner(owner);
|
||||
group.setDateOfCreation(new Date().getTime());
|
||||
group.setDateOfLastUpdate(new Date().getTime());
|
||||
try {
|
||||
DeviceMgtAPIUtils.getGroupManagementProviderService().createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
return Response.status(Response.Status.CREATED).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while adding new group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (GroupAlreadyExistException e) {
|
||||
String msg = "Group already exists with name '" + group.getName() + "'.";
|
||||
log.warn(msg);
|
||||
return Response.status(Response.Status.CONFLICT).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getGroup(int groupId) {
|
||||
try {
|
||||
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
||||
DeviceGroup deviceGroup = service.getGroup(groupId);
|
||||
if (deviceGroup != null) {
|
||||
return Response.status(Response.Status.OK).entity(deviceGroup).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String error = "Error occurred while getting the group.";
|
||||
log.error(error, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response updateGroup(int groupId, DeviceGroup deviceGroup) {
|
||||
if (deviceGroup == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
try {
|
||||
DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupId);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while adding new group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (GroupAlreadyExistException e) {
|
||||
String msg = "There is another group already exists with name '" + deviceGroup.getName() + "'.";
|
||||
log.warn(msg);
|
||||
return Response.status(Response.Status.CONFLICT).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response deleteGroup(int groupId) {
|
||||
try {
|
||||
if (DeviceMgtAPIUtils.getGroupManagementProviderService().deleteGroup(groupId)) {
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Group not found.").build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while deleting the group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response manageGroupSharing(int groupId, DeviceGroupShare deviceGroupShare) {
|
||||
try {
|
||||
DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||
.manageGroupSharing(groupId, deviceGroupShare.getUsername(), deviceGroupShare.getGroupRoles());
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while managing group share.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (RoleDoesNotExistException | UserDoesNotExistException e) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getUsersOfGroup(int groupId) {
|
||||
try {
|
||||
List<GroupUser> groupUsers = DeviceMgtAPIUtils.getGroupManagementProviderService().getUsers(groupId);
|
||||
if (groupUsers != null && groupUsers.size() > 0) {
|
||||
DeviceGroupUsersList deviceGroupUsersList = new DeviceGroupUsersList();
|
||||
deviceGroupUsersList.setList(groupUsers);
|
||||
deviceGroupUsersList.setCount(groupUsers.size());
|
||||
return Response.status(Response.Status.OK).entity(deviceGroupUsersList).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while getting users of the group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getRolesOfGroup(int groupId, String userName) {
|
||||
try {
|
||||
List<String> groupRoles;
|
||||
if(userName != null) {
|
||||
groupRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(userName, groupId);
|
||||
} else {
|
||||
groupRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupId);
|
||||
}
|
||||
|
||||
if(groupRoles != null && groupRoles.size() > 0) {
|
||||
RoleList deviceGroupRolesList = new RoleList();
|
||||
deviceGroupRolesList.setList(groupRoles);
|
||||
deviceGroupRolesList.setCount(groupRoles.size());
|
||||
return Response.status(Response.Status.OK).entity(deviceGroupRolesList).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.OK).entity(EMPTY_RESULT).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while getting roles of the group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error while retrieving the user.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getDevicesOfGroup(int groupId, int offset, int limit) {
|
||||
try {
|
||||
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
||||
List<Device> deviceList = service.getDevices(groupId, offset, limit);
|
||||
if (deviceList != null && deviceList.size() > 0) {
|
||||
DeviceList deviceListWrapper = new DeviceList();
|
||||
deviceListWrapper.setList(deviceList);
|
||||
deviceListWrapper.setCount(service.getDeviceCount(groupId));
|
||||
return Response.status(Response.Status.OK).entity(deviceListWrapper).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while getting devices the group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getDeviceCountOfGroup(int groupId) {
|
||||
try {
|
||||
int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId);
|
||||
return Response.status(Response.Status.OK).entity(count).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while getting device count of the group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response addDevicesToGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers) {
|
||||
try {
|
||||
DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while adding devices to group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (DeviceNotFoundException e) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response removeDevicesFromGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers) {
|
||||
try {
|
||||
DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(groupId, deviceIdentifiers);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while removing devices from group.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (DeviceNotFoundException e) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -231,8 +231,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
policyDeleted = false;
|
||||
}
|
||||
}
|
||||
if(policyDeleted) {
|
||||
for(int i : policyIds) {
|
||||
if (policyDeleted) {
|
||||
for (int i : policyIds) {
|
||||
Policy policy = pap.getPolicy(i);
|
||||
pap.deletePolicy(policy);
|
||||
}
|
||||
@ -244,13 +244,16 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
if (policyDeleted) {
|
||||
return Response.status(Response.Status.OK).entity("Policies have been successfully deleted").build();
|
||||
return Response.status(Response.Status.OK).entity("Policies have been successfully " +
|
||||
"deleted").build();
|
||||
} else {
|
||||
//TODO:Check of this logic is correct
|
||||
String ModifiedInvalidPolicyIds = invalidPolicyIds.substring(0, invalidPolicyIds.length()-1);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("Policies with the policy ID " +
|
||||
ModifiedInvalidPolicyIds + " doesn't exist").build()).build();
|
||||
String modifiedInvalidPolicyIds =
|
||||
invalidPolicyIds.substring(0, invalidPolicyIds.length() - 1);
|
||||
return Response.status(Response.Status.BAD_REQUEST).
|
||||
entity(new ErrorResponse.ErrorResponseBuilder().
|
||||
setMessage("Policies with the policy ID " + modifiedInvalidPolicyIds +
|
||||
" doesn't exist").build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.GroupManagementAdminService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupManagementAdminServiceImpl implements GroupManagementAdminService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GroupManagementAdminServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public Response getGroups(String name, String owner, int offset, int limit) {
|
||||
try {
|
||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
||||
GroupPaginationRequest request = new GroupPaginationRequest(offset, limit);
|
||||
request.setGroupName(name);
|
||||
request.setOwner(owner);
|
||||
PaginationResult deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||
.getGroups(request);
|
||||
if (deviceGroupsResult.getData() != null && deviceGroupsResult.getRecordsTotal() > 0) {
|
||||
DeviceGroupList deviceGroupList = new DeviceGroupList();
|
||||
deviceGroupList.setList(deviceGroupsResult.getData());
|
||||
deviceGroupList.setCount(deviceGroupsResult.getRecordsTotal());
|
||||
return Response.status(Response.Status.OK).entity(deviceGroupList).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving all groups.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getGroupCount() {
|
||||
try {
|
||||
int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount();
|
||||
return Response.status(Response.Status.OK).entity(count).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving group count.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -345,4 +345,12 @@ public class RequestValidationUtil {
|
||||
|
||||
}
|
||||
|
||||
public static void validateOwnerParameter(String owner) {
|
||||
if (owner == null || owner.isEmpty()) {
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter owner should" +
|
||||
" be non empty.").build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@
|
||||
<ref bean="roleManagementService"/>
|
||||
<ref bean="userManagementService"/>
|
||||
<ref bean="userManagementAdminService"/>
|
||||
<!--<ref bean="groupManagementService"/>-->
|
||||
<!--ref bean="groupManagementAdminService"/> -->
|
||||
<ref bean="groupManagementService"/>
|
||||
<ref bean="groupManagementAdminService"/>
|
||||
<ref bean="applicationManagementAdminService"/>
|
||||
<ref bean="deviceTypeManagementAdminService"/>
|
||||
<ref bean="dashboardServiceBean"/>
|
||||
@ -73,10 +73,10 @@
|
||||
<bean id="policyManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.PolicyManagementServiceImpl"/>
|
||||
<bean id="roleManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.RoleManagementServiceImpl"/>
|
||||
<bean id="userManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.UserManagementServiceImpl"/>
|
||||
<!--bean id="groupManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.GroupManagementServiceImpl"/>-->
|
||||
<bean id="groupManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.GroupManagementServiceImpl"/>
|
||||
<bean id="deviceManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceManagementAdminServiceImpl"/>
|
||||
<bean id="applicationManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.ApplicationManagementAdminServiceImpl"/>
|
||||
<!--bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/>-->
|
||||
<bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/>
|
||||
<bean id="userManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.UserManagementAdminServiceImpl"/>
|
||||
<bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DashboardImpl"/>
|
||||
<bean id="deviceTypeManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceTypeManagementServiceImpl"/>
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
public class DeviceNotFoundException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311996070297L;
|
||||
|
||||
public DeviceNotFoundException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public DeviceNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DeviceNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public DeviceNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DeviceNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
/**
|
||||
* This class holds required parameters for a querying a paginated device group response.
|
||||
*/
|
||||
public class GroupPaginationRequest {
|
||||
|
||||
private int startIndex;
|
||||
private int rowCount;
|
||||
private String owner;
|
||||
private String groupName;
|
||||
|
||||
public GroupPaginationRequest(int start, int rowCount) {
|
||||
this.startIndex = start;
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
public int getStartIndex() {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
this.startIndex = startIndex;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public void setRowCount(int rowCount) {
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,12 +21,13 @@ package org.wso2.carbon.device.mgt.common;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* This class holds required parameters for a querying a paginated response.
|
||||
* This class holds required parameters for a querying a paginated device response.
|
||||
*/
|
||||
public class PaginationRequest {
|
||||
|
||||
private int startIndex;
|
||||
private int rowCount;
|
||||
private int groupId;
|
||||
private String owner;
|
||||
private String status;
|
||||
private String deviceType;
|
||||
@ -55,6 +56,14 @@ public class PaginationRequest {
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(int groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common.group.mgt;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.Serializable;
|
||||
@ -25,28 +28,34 @@ import java.util.List;
|
||||
/**
|
||||
* Holds Device Group details and expose to external access
|
||||
*/
|
||||
@XmlRootElement
|
||||
@ApiModel(value = "DeviceGroup", description = "This class carries all information related to a managed device group.")
|
||||
public class DeviceGroup implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1998121711L;
|
||||
|
||||
@ApiModelProperty(name = "id", value = "ID of the device group in the device group information database.")
|
||||
private int id;
|
||||
|
||||
@ApiModelProperty(name = "description", value = "The device group description that can be set on the device group by the user.",
|
||||
required = true)
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(name = "name", value = "The device group name that can be set on the device group by the user.",
|
||||
required = true)
|
||||
private String name;
|
||||
|
||||
private Long dateOfCreation;
|
||||
private Long dateOfLastUpdate;
|
||||
private String owner;
|
||||
private List<GroupUser> users;
|
||||
private List<String> roles;
|
||||
|
||||
@XmlElement
|
||||
public int getId() {
|
||||
public int getGroupId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setGroupId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -55,7 +64,6 @@ public class DeviceGroup implements Serializable {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -64,7 +72,6 @@ public class DeviceGroup implements Serializable {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Long getDateOfCreation() {
|
||||
return dateOfCreation;
|
||||
}
|
||||
@ -73,7 +80,6 @@ public class DeviceGroup implements Serializable {
|
||||
this.dateOfCreation = dateOfCreation;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Long getDateOfLastUpdate() {
|
||||
return dateOfLastUpdate;
|
||||
}
|
||||
@ -82,7 +88,6 @@ public class DeviceGroup implements Serializable {
|
||||
this.dateOfLastUpdate = dateOfLastUpdate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
@ -91,35 +96,4 @@ public class DeviceGroup implements Serializable {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<GroupUser> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
protected void setUsers(List<GroupUser> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
protected void setRoles(List<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
protected DeviceGroup getGroup() {
|
||||
DeviceGroup deviceGroup = new DeviceGroup();
|
||||
deviceGroup.setId(getId());
|
||||
deviceGroup.setDescription(getDescription());
|
||||
deviceGroup.setName(getName());
|
||||
deviceGroup.setDateOfCreation(getDateOfCreation());
|
||||
deviceGroup.setDateOfLastUpdate(getDateOfLastUpdate());
|
||||
deviceGroup.setOwner(getOwner());
|
||||
deviceGroup.setUsers(getUsers());
|
||||
deviceGroup.setRoles(getRoles());
|
||||
return deviceGroup;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common.group.mgt;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.Serializable;
|
||||
@ -26,12 +29,17 @@ import java.util.List;
|
||||
/**
|
||||
* This class holds Device Group user name and assigned group roles of user. Exposed to external access
|
||||
*/
|
||||
@XmlRootElement
|
||||
@ApiModel(value = "GroupUser", description = "This class carries all information related to a user of a managed device group.")
|
||||
public class GroupUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1998131711L;
|
||||
|
||||
@ApiModelProperty(name = "username", value = "Username of the user.", required = true)
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(name = "roles", value = "List of roles assigned to the user.")
|
||||
private List<String> groupRoles;
|
||||
|
||||
@XmlElement
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
@ -40,7 +48,6 @@ public class GroupUser implements Serializable {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<String> getGroupRoles() {
|
||||
return groupRoles;
|
||||
}
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.common.group.mgt;
|
||||
|
||||
/**
|
||||
* This class represents a custom exception specified for group management
|
||||
*/
|
||||
public class RoleDoesNotExistException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -312678379574556874L;
|
||||
private String errorMessage;
|
||||
|
||||
public RoleDoesNotExistException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public RoleDoesNotExistException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public RoleDoesNotExistException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public RoleDoesNotExistException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RoleDoesNotExistException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
||||
Iterator<DeviceGroup> groupsWithDeviceIterator = groupsWithDevice.iterator();
|
||||
while (groupsWithDeviceIterator.hasNext()) {
|
||||
DeviceGroup deviceGroup = groupsWithDeviceIterator.next();
|
||||
if (deviceGroup.getId() == group.getId()) {
|
||||
if (deviceGroup.getGroupId() == group.getGroupId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
public class PaginationConfiguration {
|
||||
|
||||
private int deviceListPageSize;
|
||||
private int groupListPageSize;
|
||||
private int operationListPageSize;
|
||||
private int notificationListPageSize;
|
||||
private int activityListPageSize;
|
||||
@ -41,6 +42,15 @@ public class PaginationConfiguration {
|
||||
this.deviceListPageSize = deviceListPageSize;
|
||||
}
|
||||
|
||||
public int getGroupListPageSize() {
|
||||
return groupListPageSize;
|
||||
}
|
||||
|
||||
@XmlElement(name = "GroupListPageSize", required = true)
|
||||
public void setGroupListPageSize(int groupListPageSize) {
|
||||
this.groupListPageSize = groupListPageSize;
|
||||
}
|
||||
|
||||
public int getOperationListPageSize() {
|
||||
return operationListPageSize;
|
||||
}
|
||||
|
||||
@ -16,11 +16,11 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.group.mgt.dao;
|
||||
package org.wso2.carbon.device.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.DeviceGroupBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -41,24 +41,22 @@ public interface GroupDAO {
|
||||
/**
|
||||
* Update an existing Device Group.
|
||||
*
|
||||
* @param deviceGroup group to update.
|
||||
* @param oldGroupName of the group.
|
||||
* @param oldOwner of the group.
|
||||
* @param tenantId of the group.
|
||||
* @param deviceGroup group to update.
|
||||
* @param groupId of Device Group.
|
||||
* @param tenantId of the group.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner, int tenantId)
|
||||
void updateGroup(DeviceGroup deviceGroup, int groupId, int tenantId)
|
||||
throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete an existing Device Group.
|
||||
*
|
||||
* @param groupName to be deleted.
|
||||
* @param owner of the group.
|
||||
* @param groupId of Device Group.
|
||||
* @param tenantId of the group.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
void deleteGroup(String groupName, String owner, int tenantId) throws GroupManagementDAOException;
|
||||
void deleteGroup(int groupId, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get device group by id.
|
||||
@ -68,39 +66,34 @@ public interface GroupDAO {
|
||||
* @return Device Group in tenant with specified name.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
DeviceGroupBuilder getGroup(int groupId, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
|
||||
/**
|
||||
* Get device group by name.
|
||||
*
|
||||
* @param groupName of Device Group.
|
||||
* @param owner of the group.
|
||||
* @param tenantId of the group.
|
||||
* @return Device Group in tenant with specified name.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
DeviceGroupBuilder getGroup(String groupName, String owner, int tenantId) throws GroupManagementDAOException;
|
||||
DeviceGroup getGroup(int groupId, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get the groups of device with device id provided
|
||||
* @param deviceId
|
||||
* @return
|
||||
* @return groups which has the device.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
List<DeviceGroupBuilder> getGroups(int deviceId, int tenantId) throws GroupManagementDAOException;
|
||||
List<DeviceGroup> getGroups(int deviceId, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get the list of Device Groups in tenant.
|
||||
* Get paginated list of Device Groups in tenant.
|
||||
*
|
||||
* @param startIndex for pagination.
|
||||
* @param rowCount for pagination.
|
||||
* @param paginationRequest to filter results.
|
||||
* @param tenantId of user's tenant.
|
||||
* @return List of all Device Groups in tenant.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
List<DeviceGroupBuilder> getGroups(int startIndex, int rowCount, int tenantId) throws GroupManagementDAOException;
|
||||
List<DeviceGroup> getGroups(GroupPaginationRequest paginationRequest, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get the list of Device Groups in tenant.
|
||||
*
|
||||
* @param tenantId of user's tenant.
|
||||
* @return List of all Device Groups in tenant.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
List<DeviceGroup> getGroups(int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get count of Device Groups in tenant.
|
||||
@ -112,94 +105,77 @@ public interface GroupDAO {
|
||||
int getGroupCount(int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get the list of Groups that matches with the given DeviceGroup name.
|
||||
* Get paginated count of Device Groups in tenant.
|
||||
*
|
||||
* @param groupName of the Device Group.
|
||||
* @param tenantId of user's tenant.
|
||||
* @return List of DeviceGroup that matches with the given DeviceGroup name.
|
||||
* @param paginationRequest to filter results.
|
||||
* @param tenantId of user's tenant.
|
||||
* @return List of all Device Groups in tenant.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
List<DeviceGroupBuilder> findInGroups(String groupName, int tenantId) throws GroupManagementDAOException;
|
||||
int getGroupCount(GroupPaginationRequest paginationRequest, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Check group already existed with given name.
|
||||
*
|
||||
* @param groupName of the Device Group.
|
||||
* @param owner of the Device Group.
|
||||
* @param tenantId of user's tenant.
|
||||
* @return existence of group with name
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
boolean isGroupExist(String groupName, String owner, int tenantId) throws GroupManagementDAOException;
|
||||
DeviceGroup getGroup(String groupName, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Add device to a given Device Group.
|
||||
*
|
||||
* @param groupName of the Device Group.
|
||||
* @param owner of the Device Group.
|
||||
* @param groupId of Device Group.
|
||||
* @param deviceId of the device.
|
||||
* @param tenantId of user's tenant.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
void addDevice(String groupName, String owner, int deviceId, int tenantId) throws GroupManagementDAOException;
|
||||
void addDevice(int groupId, int deviceId, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Remove device from the Device Group.
|
||||
*
|
||||
* @param groupName of the Device Group.
|
||||
* @param owner of the Device Group.
|
||||
* @param groupId of Device Group.
|
||||
* @param deviceId of the device.
|
||||
* @param tenantId of user's tenant.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
void removeDevice(String groupName, String owner, int deviceId, int tenantId) throws GroupManagementDAOException;
|
||||
void removeDevice(int groupId, int deviceId, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Check device is belonging to a Device Group.
|
||||
*
|
||||
* @param groupName of the Device Group.
|
||||
* @param owner of the Device Group.
|
||||
* @param groupId of Device Group.
|
||||
* @param deviceId of the device.
|
||||
* @param tenantId of user's tenant.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
boolean isDeviceMappedToGroup(String groupName, String owner, int deviceId, int tenantId)
|
||||
boolean isDeviceMappedToGroup(int groupId, int deviceId, int tenantId)
|
||||
throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get count of devices in a Device Group.
|
||||
*
|
||||
* @param groupName of the Device Group.
|
||||
* @param owner of the Device Group.
|
||||
* @param groupId of Device Group.
|
||||
* @param tenantId of user's tenant.
|
||||
* @return device count.
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
int getDeviceCount(String groupName, String owner, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get all devices of a given tenant and device group.
|
||||
*
|
||||
* @param groupName of the group.
|
||||
* @param owner of the Device Group.
|
||||
* @param tenantId of user's tenant.
|
||||
* @return list of device in group
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
List<Device> getDevices(String groupName, String owner, int tenantId) throws GroupManagementDAOException;
|
||||
int getDeviceCount(int groupId, int tenantId) throws GroupManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get paginated result of devices of a given tenant and device group.
|
||||
*
|
||||
* @param groupName of the group.
|
||||
* @param owner of the Device Group.
|
||||
* @param groupId of Device Group.
|
||||
* @param startIndex for pagination.
|
||||
* @param rowCount for pagination.
|
||||
* @param tenantId of user's tenant.
|
||||
* @return list of device in group
|
||||
* @throws GroupManagementDAOException
|
||||
*/
|
||||
List<Device> getDevices(String groupName, String owner, int startIndex, int rowCount, int tenantId)
|
||||
List<Device> getDevices(int groupId, int startIndex, int rowCount, int tenantId)
|
||||
throws GroupManagementDAOException;
|
||||
|
||||
}
|
||||
@ -16,7 +16,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.group.mgt.dao;
|
||||
package org.wso2.carbon.device.mgt.core.dao;
|
||||
|
||||
/**
|
||||
* Custom exception class for group management data access related exceptions.
|
||||
@ -16,7 +16,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.group.mgt.dao;
|
||||
package org.wso2.carbon.device.mgt.core.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -24,6 +24,8 @@ import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.GroupDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.GroupManagementDAOUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
@ -28,7 +28,6 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.utils.xml.StringUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
@ -16,12 +16,16 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.group.mgt.dao;
|
||||
package org.wso2.carbon.device.mgt.core.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.DeviceGroupBuilder;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.GroupManagementDAOUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -67,21 +71,20 @@ public class GroupDAOImpl implements GroupDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner, int tenantId)
|
||||
public void updateGroup(DeviceGroup deviceGroup, int groupId, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, DATE_OF_LAST_UPDATE = ?, OWNER = ? "
|
||||
+ "WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?";
|
||||
+ "WHERE ID = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceGroup.getDescription());
|
||||
stmt.setString(2, deviceGroup.getName());
|
||||
stmt.setLong(3, deviceGroup.getDateOfLastUpdate());
|
||||
stmt.setString(4, deviceGroup.getOwner());
|
||||
stmt.setString(5, oldGroupName);
|
||||
stmt.setString(6, oldOwner);
|
||||
stmt.setInt(7, tenantId);
|
||||
stmt.setInt(5, groupId);
|
||||
stmt.setInt(6, tenantId);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while updating deviceGroup '" +
|
||||
@ -92,42 +95,38 @@ public class GroupDAOImpl implements GroupDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGroup(String groupName, String owner, int tenantId) throws GroupManagementDAOException {
|
||||
public void deleteGroup(int groupId, int tenantId) throws GroupManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE GROUP_ID = (SELECT ID AS GROUP_ID FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?) AND TENANT_ID = ?";
|
||||
String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE GROUP_ID = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while removing mappings for group '" + groupName +
|
||||
"'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while removing mappings for group.'", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
|
||||
try {
|
||||
conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?";
|
||||
String sql = "DELETE FROM DM_GROUP WHERE ID = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while deleting group '" + groupName + "'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while deleting group.'", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceGroupBuilder getGroup(int groupId, int tenantId) throws GroupManagementDAOException {
|
||||
public DeviceGroup getGroup(int groupId, int tenantId) throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
@ -152,38 +151,10 @@ public class GroupDAOImpl implements GroupDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceGroupBuilder getGroup(String groupName, String owner, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
public List<DeviceGroup> getGroups(int deviceId, int tenantId) throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER "
|
||||
+ "FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(3, tenantId);
|
||||
resultSet = stmt.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return GroupManagementDAOUtil.loadGroup(resultSet);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while obtaining information of Device Group '" +
|
||||
groupName + "'", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceGroupBuilder> getGroups(int deviceId, int tenantId) throws GroupManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
List<DeviceGroupBuilder> deviceGroupBuilders = new ArrayList<>();
|
||||
List<DeviceGroup> deviceGroupBuilders = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT G.ID, G.GROUP_NAME, G.DESCRIPTION, G.DATE_OF_CREATE, G.DATE_OF_LAST_UPDATE, \n" +
|
||||
@ -205,21 +176,71 @@ public class GroupDAOImpl implements GroupDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceGroupBuilder> getGroups(int startIndex, int rowCount, int tenantId)
|
||||
public List<DeviceGroup> getGroups(GroupPaginationRequest request, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
List<DeviceGroupBuilder> deviceGroupList = null;
|
||||
List<DeviceGroup> deviceGroupList = null;
|
||||
|
||||
String groupName = request.getGroupName();
|
||||
boolean hasGroupName = false;
|
||||
String owner = request.getOwner();
|
||||
boolean hasOwner = false;
|
||||
boolean hasLimit = request.getRowCount() != 0;
|
||||
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER "
|
||||
+ "FROM DM_GROUP WHERE TENANT_ID = ? LIMIT ?, ?";
|
||||
+ "FROM DM_GROUP WHERE TENANT_ID = ?";
|
||||
if (groupName != null && !groupName.isEmpty()) {
|
||||
sql += " AND GROUP_NAME LIKE ?";
|
||||
hasGroupName = true;
|
||||
}
|
||||
if (owner != null && !owner.isEmpty()) {
|
||||
sql += " AND OWNER LIKE ?";
|
||||
hasOwner = true;
|
||||
}
|
||||
if (hasLimit) {
|
||||
sql += " LIMIT ?, ?";
|
||||
}
|
||||
|
||||
int paramIndex = 1;
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(paramIndex++, tenantId);
|
||||
if (hasGroupName) {
|
||||
stmt.setString(paramIndex++, groupName + "%");
|
||||
}
|
||||
if (hasOwner) {
|
||||
stmt.setString(paramIndex++, owner + "%");
|
||||
}
|
||||
if (hasLimit) {
|
||||
stmt.setInt(paramIndex++, request.getStartIndex());
|
||||
stmt.setInt(paramIndex, request.getRowCount());
|
||||
}
|
||||
resultSet = stmt.executeQuery();
|
||||
deviceGroupList = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
deviceGroupList.add(GroupManagementDAOUtil.loadGroup(resultSet));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while listing all groups in tenant: " + tenantId, e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return deviceGroupList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceGroup> getGroups(int tenantId) throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
List<DeviceGroup> deviceGroupList = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER "
|
||||
+ "FROM DM_GROUP WHERE TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
//noinspection JpaQueryApiInspection
|
||||
stmt.setInt(2, startIndex);
|
||||
//noinspection JpaQueryApiInspection
|
||||
stmt.setInt(3, rowCount);
|
||||
resultSet = stmt.executeQuery();
|
||||
deviceGroupList = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
@ -256,140 +277,144 @@ public class GroupDAOImpl implements GroupDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceGroupBuilder> findInGroups(String groupName, int tenantId)
|
||||
public int getGroupCount(GroupPaginationRequest request, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
List<DeviceGroupBuilder> deviceGroups = new ArrayList<>();
|
||||
|
||||
String groupName = request.getGroupName();
|
||||
boolean hasGroupName = false;
|
||||
String owner = request.getOwner();
|
||||
boolean hasOwner = false;
|
||||
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER "
|
||||
+ "FROM DM_GROUP WHERE GROUP_NAME LIKE ? AND TENANT_ID = ?";
|
||||
String sql = "SELECT COUNT(ID) AS GROUP_COUNT FROM DM_GROUP WHERE TENANT_ID = ?";
|
||||
if (groupName != null && !groupName.isEmpty()) {
|
||||
sql += " AND GROUP_NAME LIKE ?";
|
||||
hasGroupName = true;
|
||||
}
|
||||
if (owner != null && !owner.isEmpty()) {
|
||||
sql += " AND OWNER LIKE ?";
|
||||
hasOwner = true;
|
||||
}
|
||||
|
||||
int paramIndex = 1;
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, "%" + groupName + "%");
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.setInt(paramIndex++, tenantId);
|
||||
if (hasGroupName) {
|
||||
stmt.setString(paramIndex++, groupName + "%");
|
||||
}
|
||||
if (hasOwner) {
|
||||
stmt.setString(paramIndex, owner + "%");
|
||||
}
|
||||
resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
deviceGroups.add(GroupManagementDAOUtil.loadGroup(resultSet));
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt("GROUP_COUNT");
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while listing Device Groups by name '" +
|
||||
groupName + "' in tenant '" + tenantId + "'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while listing all groups in tenant: " + tenantId, e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return deviceGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGroupExist(String groupName, String owner, int tenantId) throws GroupManagementDAOException {
|
||||
public DeviceGroup getGroup(String groupName, int tenantId) throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT GROUP_NAME FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?";
|
||||
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER " +
|
||||
"FROM DM_GROUP WHERE GROUP_NAME = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
resultSet = stmt.executeQuery();
|
||||
return resultSet.next();
|
||||
if (resultSet.next()) {
|
||||
return GroupManagementDAOUtil.loadGroup(resultSet);
|
||||
}
|
||||
return null;
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while group Id listing by group name '" +
|
||||
groupName + "'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while group Id listing by group name.'", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(String groupName, String owner, int deviceId, int tenantId)
|
||||
public void addDevice(int groupId, int deviceId, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "INSERT INTO DM_DEVICE_GROUP_MAP(DEVICE_ID, GROUP_ID, TENANT_ID) " +
|
||||
"VALUES (?, (SELECT ID as GROUP_ID FROM DM_GROUP " +
|
||||
"WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?), ?)";
|
||||
String sql = "INSERT INTO DM_DEVICE_GROUP_MAP(DEVICE_ID, GROUP_ID, TENANT_ID) VALUES (?, ?, ?)";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setString(2, groupName);
|
||||
stmt.setString(3, owner);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.setInt(5, tenantId);
|
||||
stmt.setInt(2, groupId);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.executeUpdate();
|
||||
stmt.getGeneratedKeys();
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while adding device to Group '" + groupName + "'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while adding device to Group.", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDevice(String groupName, String owner, int deviceId, int tenantId)
|
||||
public void removeDevice(int groupId, int deviceId, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE DEVICE_ID = ? AND GROUP_ID = (SELECT ID as GROUP_ID " +
|
||||
"FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?) AND TENANT_ID = ?";
|
||||
String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE DEVICE_ID = ? AND GROUP_ID = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setString(2, groupName);
|
||||
stmt.setString(3, owner);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.setInt(5, tenantId);
|
||||
stmt.setInt(2, groupId);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.executeUpdate();
|
||||
stmt.getGeneratedKeys();
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while removing device from Group '" +
|
||||
groupName + "'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while removing device from Group.", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeviceMappedToGroup(String groupName, String owner, int deviceId, int tenantId)
|
||||
public boolean isDeviceMappedToGroup(int groupId, int deviceId, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT dm.ID FROM DM_DEVICE_GROUP_MAP dm, (SELECT ID as GROUP_ID FROM DM_GROUP " +
|
||||
"WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?) dg " +
|
||||
"WHERE dm.GROUP_ID = dg.GROUP_ID AND dm.ID = ? AND dm.TENANT_ID = ?";
|
||||
String sql = "SELECT ID FROM DM_DEVICE_GROUP_MAP WHERE GROUP_ID = ? AND DEVICE_ID = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(4, deviceId);
|
||||
stmt.setInt(5, tenantId);
|
||||
resultSet = stmt.executeQuery();
|
||||
return resultSet.next();
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while group Id listing by group name '" +
|
||||
groupName + "'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while checking device mapping with group.", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDeviceCount(String groupName, String owner, int tenantId) throws GroupManagementDAOException {
|
||||
public int getDeviceCount(int groupId, int tenantId) throws GroupManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT COUNT(gm.ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP gm, (SELECT ID " +
|
||||
"FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?) dg " +
|
||||
"WHERE gm.GROUP_ID = dg.ID AND gm.TENANT_ID = ?";
|
||||
String sql = "SELECT COUNT(ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP WHERE GROUP_ID = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, tenantId);
|
||||
resultSet = stmt.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt("DEVICE_COUNT");
|
||||
@ -397,54 +422,15 @@ public class GroupDAOImpl implements GroupDAO {
|
||||
return 0;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while group Id listing by group name '" +
|
||||
groupName + "'", e);
|
||||
throw new GroupManagementDAOException("Error occurred while getting device count from the group.", e);
|
||||
} finally {
|
||||
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Move this to device mgt
|
||||
@Override
|
||||
public List<Device> getDevices(String groupName, String owner, int tenantId) throws GroupManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Device> devices = null;
|
||||
try {
|
||||
conn = GroupManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
||||
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, " +
|
||||
"t.NAME AS DEVICE_TYPE FROM (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME, " +
|
||||
"d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID FROM DM_DEVICE d, (SELECT dgm.DEVICE_ID " +
|
||||
"FROM DM_DEVICE_GROUP_MAP dgm, DM_GROUP dg WHERE dgm.GROUP_ID = dg.ID AND dg.GROUP_NAME = ? " +
|
||||
"AND dg.OWNER = ? AND dg.TENANT_ID = ?) dgm1 WHERE d.ID = dgm1.DEVICE_ID " +
|
||||
"AND d.TENANT_ID = ?) gd, DM_DEVICE_TYPE t WHERE gd.DEVICE_TYPE_ID = t.ID) d1 " +
|
||||
"WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.setInt(5, tenantId);
|
||||
rs = stmt.executeQuery();
|
||||
devices = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||
devices.add(device);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementDAOException("Error occurred while retrieving information of all " +
|
||||
"registered devices", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getDevices(String groupName, String owner, int startIndex, int rowCount, int tenantId)
|
||||
public List<Device> getDevices(int groupId, int startIndex, int rowCount, int tenantId)
|
||||
throws GroupManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
@ -455,24 +441,20 @@ public class GroupDAOImpl implements GroupDAO {
|
||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
||||
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, " +
|
||||
"t.NAME AS DEVICE_TYPE FROM (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME, " +
|
||||
"d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID FROM DM_DEVICE d, (SELECT dgm.DEVICE_ID " +
|
||||
"FROM DM_DEVICE_GROUP_MAP dgm, DM_GROUP dg WHERE dgm.GROUP_ID = dg.ID AND dg.GROUP_NAME = ? " +
|
||||
"AND dg.OWNER = ? AND dg.TENANT_ID = ?) dgm1 WHERE d.ID = dgm1.DEVICE_ID " +
|
||||
"AND d.TENANT_ID = ?) gd, DM_DEVICE_TYPE t WHERE gd.DEVICE_TYPE_ID = t.ID) d1 " +
|
||||
"WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ?, ?";
|
||||
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"(SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID FROM DM_DEVICE d, (" +
|
||||
"SELECT dgm.DEVICE_ID FROM DM_DEVICE_GROUP_MAP dgm WHERE dgm.GROUP_ID = ?) dgm1 " +
|
||||
"WHERE d.ID = dgm1.DEVICE_ID AND d.TENANT_ID = ?) gd, DM_DEVICE_TYPE t " +
|
||||
"WHERE gd.DEVICE_TYPE_ID = t.ID) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ? , ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, groupName);
|
||||
stmt.setString(2, owner);
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.setInt(5, tenantId);
|
||||
//noinspection JpaQueryApiInspection
|
||||
stmt.setInt(6, startIndex);
|
||||
stmt.setInt(4, startIndex);
|
||||
//noinspection JpaQueryApiInspection
|
||||
stmt.setInt(7, rowCount);
|
||||
stmt.setInt(5, rowCount);
|
||||
rs = stmt.executeQuery();
|
||||
devices = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
@ -16,12 +16,11 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.group.mgt.dao;
|
||||
package org.wso2.carbon.device.mgt.core.dao.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.DeviceGroupBuilder;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.sql.DataSource;
|
||||
@ -80,8 +79,8 @@ public final class GroupManagementDAOUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static DeviceGroupBuilder loadGroup(ResultSet resultSet) throws SQLException {
|
||||
DeviceGroupBuilder group = new DeviceGroupBuilder(new DeviceGroup());
|
||||
public static DeviceGroup loadGroup(ResultSet resultSet) throws SQLException {
|
||||
DeviceGroup group = new DeviceGroup();
|
||||
group.setGroupId(resultSet.getInt("ID"));
|
||||
group.setDescription(resultSet.getString("DESCRIPTION"));
|
||||
group.setName(resultSet.getString("GROUP_NAME"));
|
||||
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.group.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is used to expose protected methods to the core. Use with internal access only.
|
||||
*/
|
||||
public class DeviceGroupBuilder extends DeviceGroup {
|
||||
|
||||
private int groupId;
|
||||
|
||||
/**
|
||||
* Set device group to be decorated with the builder
|
||||
*
|
||||
* @param deviceGroup to decorate
|
||||
*/
|
||||
public DeviceGroupBuilder(DeviceGroup deviceGroup) {
|
||||
this.setId(deviceGroup.getId());
|
||||
this.setDescription(deviceGroup.getDescription());
|
||||
this.setName(deviceGroup.getName());
|
||||
this.setDateOfCreation(deviceGroup.getDateOfCreation());
|
||||
this.setDateOfLastUpdate(deviceGroup.getDateOfLastUpdate());
|
||||
this.setOwner(deviceGroup.getOwner());
|
||||
this.setUsers(deviceGroup.getUsers());
|
||||
this.setRoles(deviceGroup.getRoles());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsers(List<GroupUser> users) {
|
||||
super.setUsers(users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRoles(List<String> roles) {
|
||||
super.setRoles(roles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceGroup getGroup() {
|
||||
return super.getGroup();
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(int groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,7 @@ import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
package org.wso2.carbon.device.mgt.core.notification.mgt.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
|
||||
|
||||
@ -307,14 +307,14 @@ public class OperationManagerImpl implements OperationManager {
|
||||
throws OperationManagementException {
|
||||
PaginationResult paginationResult = null;
|
||||
List<Operation> operations = new ArrayList<>();
|
||||
|
||||
String owner = request.getOwner();
|
||||
if (!isActionAuthorized(deviceId)) {
|
||||
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
|
||||
deviceId.getType() + "' device, which carries the identifier '" +
|
||||
deviceId.getId() + "'");
|
||||
deviceId.getId() + "' of owner '" + owner + "'" );
|
||||
}
|
||||
|
||||
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId);
|
||||
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId, owner);
|
||||
if (enrolmentInfo == null) {
|
||||
throw new OperationManagementException("Device not found for given device " +
|
||||
"Identifier:" + deviceId.getId() + " and given type" +
|
||||
@ -923,31 +923,33 @@ public class OperationManagerImpl implements OperationManager {
|
||||
return enrolmentId;
|
||||
}
|
||||
|
||||
private EnrolmentInfo getEnrolmentInfo(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
EnrolmentInfo enrolmentInfo;
|
||||
private EnrolmentInfo getEnrolmentInfo(DeviceIdentifier deviceId, String owner) throws OperationManagementException {
|
||||
EnrolmentInfo enrolmentInfo = null;
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
String user = this.getUser();
|
||||
enrolmentInfo = deviceDAO.getEnrolment(deviceId, user, tenantId);
|
||||
if (enrolmentInfo == null) {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
if (this.isSameUser(user, owner)) {
|
||||
enrolmentInfo = deviceDAO.getEnrolment(deviceId, owner, tenantId);
|
||||
} else {
|
||||
boolean isAdminUser = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||
isDeviceAdminUser();
|
||||
if (isAdminUser) {
|
||||
enrolmentInfo = deviceDAO.getEnrolment(deviceId, tenantId);
|
||||
enrolmentInfo = deviceDAO.getEnrolment(deviceId, owner, tenantId);
|
||||
}
|
||||
//TODO : Add a check for group admin if this fails
|
||||
}
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
|
||||
deviceId.getType() + "' device carrying the identifier '" +
|
||||
deviceId.getId() + "'", e);
|
||||
deviceId.getId() + "' of owner '" + owner + "'", e);
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementException(
|
||||
"Error occurred while opening a connection to the data source", e);
|
||||
} catch (DeviceAccessAuthorizationException e) {
|
||||
throw new OperationManagementException("Error occurred while checking the device access permissions for '" +
|
||||
deviceId.getType() + "' device carrying the identifier '" +
|
||||
deviceId.getId() + "'", e);
|
||||
deviceId.getId() + "' of owner '" + owner + "'", e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
@ -1021,4 +1023,8 @@ public class OperationManagerImpl implements OperationManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isSameUser(String user, String owner) {
|
||||
return user.equalsIgnoreCase(owner);
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
try {
|
||||
super.deleteOperation(id);
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
|
||||
stmt = connection.prepareStatement("DELETE FROM DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
|
||||
@ -64,7 +64,7 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
try {
|
||||
super.deleteOperation(id);
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ;
|
||||
stmt = connection.prepareStatement("DELETE FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ;
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
@ -82,7 +82,7 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
try {
|
||||
super.updateOperation(operation);
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION SET OPERATION_CONFIG = ? " +
|
||||
stmt = connection.prepareStatement("UPDATE FROM DM_CONFIG_OPERATION SET OPERATION_CONFIG = ? " +
|
||||
"WHERE OPERATION_ID = ?");
|
||||
bao = new ByteArrayOutputStream();
|
||||
oos = new ObjectOutputStream(bao);
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
||||
|
||||
import org.apache.axis2.databinding.types.soapencoding.Integer;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
@ -26,7 +25,6 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
@ -622,7 +620,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("DELETE DM_OPERATION WHERE ID = ?");
|
||||
stmt = connection.prepareStatement("DELETE FROM DM_OPERATION WHERE ID = ?");
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
@ -869,12 +867,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
||||
"OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"
|
||||
+ "LIMIT ?,?";
|
||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
/*stmt.setInt(2, request.getStartIndex());
|
||||
stmt.setInt(3, request.getRowCount());*/
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
@ -882,11 +877,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
// operation.setReceivedTimeStamp("");
|
||||
// } else {
|
||||
// operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
// }
|
||||
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
@ -895,7 +885,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
// this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@ -931,11 +920,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
// operation.setReceivedTimeStamp("");
|
||||
// } else {
|
||||
// operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
// }
|
||||
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
|
||||
@ -128,7 +128,7 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
try {
|
||||
super.deleteOperation(operationId);
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("DELETE DM_POLICY_OPERATION WHERE OPERATION_ID=?");
|
||||
stmt = connection.prepareStatement("DELETE FROM DM_POLICY_OPERATION WHERE OPERATION_ID=?");
|
||||
stmt.setInt(1, operationId);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
|
||||
@ -129,7 +129,7 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
try {
|
||||
super.deleteOperation(id);
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("DELETE DM_PROFILE_OPERATION WHERE OPERATION_ID=?");
|
||||
stmt = connection.prepareStatement("DELETE FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?");
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
|
||||
@ -90,7 +90,7 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
PaginationRequest request, Operation.Status status) throws OperationManagementDAOException {
|
||||
PaginationRequest request, Operation.Status status) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
|
||||
@ -20,11 +20,15 @@ package org.wso2.carbon.device.mgt.core.service;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
||||
import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException;
|
||||
|
||||
import java.util.List;
|
||||
@ -49,71 +53,64 @@ public interface GroupManagementProviderService {
|
||||
* Update existing device group.
|
||||
*
|
||||
* @param deviceGroup to update.
|
||||
* @param oldGroupName of the group.
|
||||
* @param oldOwner of the group.
|
||||
* @param groupId of the group.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner) throws GroupManagementException;
|
||||
void updateGroup(DeviceGroup deviceGroup, int groupId) throws GroupManagementException, GroupAlreadyExistException;
|
||||
|
||||
/**
|
||||
* Delete existing device group.
|
||||
*
|
||||
* @param groupName to be deleted.
|
||||
* @param owner of the group.
|
||||
* @param groupId to be deleted.
|
||||
* @return status of the delete operation.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
boolean deleteGroup(String groupName, String owner) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get device group specified by group name.
|
||||
*
|
||||
* @param groupName of the group.
|
||||
* @param owner of the group.
|
||||
* @return group
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
DeviceGroup getGroup(String groupName, String owner) throws GroupManagementException;
|
||||
|
||||
boolean deleteGroup(int groupId) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get the device group provided the device group id.
|
||||
*
|
||||
* @param groupId
|
||||
* @return
|
||||
* @param groupId of the group.
|
||||
* @return group with details.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
DeviceGroup getGroup(int groupId) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get list of device groups matched with %groupName%
|
||||
* Get all device groups in tenant.
|
||||
*
|
||||
* @param groupName of the groups.
|
||||
* @param username of user
|
||||
* @return List of Groups that matches with the given DeviceGroup name.
|
||||
* @return list of groups.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
List<DeviceGroup> findInGroups(String groupName, String username) throws GroupManagementException;
|
||||
List<DeviceGroup> getGroups() throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get paginated device groups in tenant
|
||||
* Get all device groups for user.
|
||||
*
|
||||
* @param startIndex for pagination.
|
||||
* @param rowCount for pagination.
|
||||
* @return paginated list of groups
|
||||
* @param username of the user.
|
||||
* @return list of groups
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
PaginationResult getGroups(int startIndex, int rowCount) throws GroupManagementException;
|
||||
List<DeviceGroup> getGroups(String username) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get paginated device groups in tenant
|
||||
* Get device groups with pagination.
|
||||
*
|
||||
* @param username of user.
|
||||
* @param startIndex for pagination.
|
||||
* @param rowCount for pagination.
|
||||
* @return paginated list of groups
|
||||
* @param paginationRequest to filter results
|
||||
* @return list of groups.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
PaginationResult getGroups(String username, int startIndex, int rowCount) throws GroupManagementException;
|
||||
PaginationResult getGroups(GroupPaginationRequest paginationRequest) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get device groups belongs to specified user with pagination.
|
||||
*
|
||||
* @param username of the user.
|
||||
* @param paginationRequest to filter results
|
||||
* @return list of groups.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
PaginationResult getGroups(String username, GroupPaginationRequest paginationRequest) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get all device group count in tenant
|
||||
@ -123,15 +120,6 @@ public interface GroupManagementProviderService {
|
||||
*/
|
||||
int getGroupCount() throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get device groups of user
|
||||
*
|
||||
* @param username of the user
|
||||
* @return list of groups
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
List<DeviceGroup> getGroups(String username) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get device group count of user
|
||||
*
|
||||
@ -142,154 +130,116 @@ public interface GroupManagementProviderService {
|
||||
int getGroupCount(String username) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Share device group with user specified by role
|
||||
* Manage device group sharing with user with list of roles.
|
||||
*
|
||||
* @param username of the user
|
||||
* @param groupName of the group
|
||||
* @param owner of the group
|
||||
* @param sharingRole to be shared
|
||||
* @return is group shared
|
||||
* @param username of the user
|
||||
* @param groupId of the group
|
||||
* @param newRoles to be shared
|
||||
* @throws GroupManagementException UserDoesNotExistException
|
||||
*/
|
||||
boolean shareGroup(String username, String groupName, String owner, String sharingRole)
|
||||
throws GroupManagementException, UserDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Un share existing group sharing with user specified by role
|
||||
*
|
||||
* @param userName of the user
|
||||
* @param groupName of the group
|
||||
* @param owner of the group
|
||||
* @param sharingRole to be un shared
|
||||
* @return is group un shared
|
||||
* @throws GroupManagementException UserDoesNotExistException
|
||||
*/
|
||||
boolean unshareGroup(String userName, String groupName, String owner, String sharingRole)
|
||||
throws GroupManagementException, UserDoesNotExistException;
|
||||
void manageGroupSharing(int groupId, String username, List<String> newRoles)
|
||||
throws GroupManagementException, UserDoesNotExistException, RoleDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Add new sharing role for device group
|
||||
*
|
||||
* @param userName of the user
|
||||
* @param groupName of the group
|
||||
* @param owner of the group
|
||||
* @param groupId of the group
|
||||
* @param roleName to add
|
||||
* @param permissions to bind with role
|
||||
* @return is role added
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
boolean addGroupSharingRole(String userName, String groupName, String owner, String roleName, String[] permissions)
|
||||
boolean addGroupSharingRole(String userName, int groupId, String roleName, String[] permissions)
|
||||
throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Remove existing sharing role for device group
|
||||
*
|
||||
* @param groupName of the group
|
||||
* @param owner of the group
|
||||
* @param groupId of the group
|
||||
* @param roleName to remove
|
||||
* @return is role removed
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
boolean removeGroupSharingRole(String groupName, String owner, String roleName) throws GroupManagementException;
|
||||
boolean removeGroupSharingRole(int groupId, String roleName) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get all sharing roles for device group
|
||||
*
|
||||
* @param groupName of the group
|
||||
* @param owner of the group
|
||||
* @param groupId of the group
|
||||
* @return list of roles
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
List<String> getRoles(String groupName, String owner) throws GroupManagementException;
|
||||
List<String> getRoles(int groupId) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get specific device group sharing roles for user
|
||||
*
|
||||
* @param userName of the user
|
||||
* @param groupName of the group
|
||||
* @param owner of the group
|
||||
* @param groupId of the group
|
||||
* @return list of roles
|
||||
* @throws GroupManagementException UserDoesNotExistException
|
||||
*/
|
||||
List<String> getRoles(String userName, String groupName, String owner)
|
||||
throws GroupManagementException, UserDoesNotExistException;
|
||||
List<String> getRoles(String userName, int groupId) throws GroupManagementException, UserDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Get device group users
|
||||
*
|
||||
* @param groupName of the group
|
||||
* @param owner of the group
|
||||
* @param groupId of the group
|
||||
* @return list of group users
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
List<GroupUser> getUsers(String groupName, String owner) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get all devices in device group.
|
||||
*
|
||||
* @param groupName of the group.
|
||||
* @param owner of the group.
|
||||
* @return list of group devices.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
List<Device> getDevices(String groupName, String owner) throws GroupManagementException;
|
||||
List<GroupUser> getUsers(int groupId) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Get all devices in device group as paginated result.
|
||||
*
|
||||
* @param groupName of the group.
|
||||
* @param owner of the group.
|
||||
* @param groupId of the group
|
||||
* @param startIndex for pagination.
|
||||
* @param rowCount for pagination.
|
||||
* @return Paginated list of devices.
|
||||
* @return list of devices in group.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
PaginationResult getDevices(String groupName, String owner, int startIndex, int rowCount)
|
||||
throws GroupManagementException;
|
||||
List<Device> getDevices(int groupId, int startIndex, int rowCount) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve the device count of a given group.
|
||||
*
|
||||
* @param groupName of the group.
|
||||
* @param owner of the group.
|
||||
* @param groupId of the group
|
||||
* @return returns the device count.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
int getDeviceCount(String groupName, String owner) throws GroupManagementException;
|
||||
int getDeviceCount(int groupId) throws GroupManagementException;
|
||||
|
||||
/**
|
||||
* Add device to device group.
|
||||
*
|
||||
* @param deviceId of the device.
|
||||
* @param groupName of the group.
|
||||
* @param owner of the group.
|
||||
* @return is device added.
|
||||
* @param groupId of the group.
|
||||
* @param deviceIdentifiers of devices.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
boolean addDevice(DeviceIdentifier deviceId, String groupName, String owner) throws GroupManagementException;
|
||||
void addDevices(int groupId, List<DeviceIdentifier> deviceIdentifiers) throws GroupManagementException,
|
||||
DeviceNotFoundException;
|
||||
|
||||
/**
|
||||
* Remove device from device group.
|
||||
*
|
||||
* @param deviceId of the device.
|
||||
* @param groupName of the group.
|
||||
* @param owner of the group.
|
||||
* @return is device removed.
|
||||
* @param groupId of the group.
|
||||
* @param deviceIdentifiers of devices.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
boolean removeDevice(DeviceIdentifier deviceId, String groupName, String owner) throws GroupManagementException;
|
||||
void removeDevice(int groupId, List<DeviceIdentifier> deviceIdentifiers) throws GroupManagementException,
|
||||
DeviceNotFoundException;
|
||||
|
||||
/**
|
||||
* Get device group permissions of user.
|
||||
*
|
||||
* @param username of the user.
|
||||
* @param groupName of the group.
|
||||
* @param owner of the group.
|
||||
* @param groupId of the group
|
||||
* @return array of permissions.
|
||||
* @throws GroupManagementException UserDoesNotExistException
|
||||
*/
|
||||
String[] getPermissions(String username, String groupName, String owner)
|
||||
throws GroupManagementException, UserDoesNotExistException;
|
||||
String[] getPermissions(String username, int groupId) throws GroupManagementException, UserDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Get device groups of user with permission.
|
||||
|
||||
@ -23,16 +23,23 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.CarbonConstants;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.DeviceGroupBuilder;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupDAO;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
import org.wso2.carbon.user.api.Permission;
|
||||
import org.wso2.carbon.user.api.UserRealm;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
@ -41,7 +48,11 @@ import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException;
|
||||
import org.wso2.carbon.user.core.util.UserCoreUtil;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GroupManagementProviderServiceImpl implements GroupManagementProviderService {
|
||||
|
||||
@ -65,14 +76,13 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
if (deviceGroup == null) {
|
||||
throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException());
|
||||
}
|
||||
DeviceGroupBuilder groupBroker = new DeviceGroupBuilder(deviceGroup);
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
int groupId = -1;
|
||||
try {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
boolean nameIsExists = this.groupDAO.isGroupExist(deviceGroup.getName(), deviceGroup.getOwner(), tenantId);
|
||||
if (!nameIsExists) {
|
||||
groupId = this.groupDAO.addGroup(groupBroker, tenantId);
|
||||
DeviceGroup existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
|
||||
if (existingGroup == null) {
|
||||
groupId = this.groupDAO.addGroup(deviceGroup, tenantId);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
} else {
|
||||
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
|
||||
@ -87,9 +97,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
|
||||
addGroupSharingRole(groupBroker.getOwner(), groupId, defaultRole, defaultPermissions);
|
||||
addGroupSharingRole(deviceGroup.getOwner(), groupId, defaultRole, defaultPermissions);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("DeviceGroup added: " + groupBroker.getName());
|
||||
log.debug("DeviceGroup added: " + deviceGroup.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,17 +107,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner)
|
||||
throws GroupManagementException {
|
||||
public void updateGroup(DeviceGroup deviceGroup, int groupId)
|
||||
throws GroupManagementException, GroupAlreadyExistException {
|
||||
if (deviceGroup == null) {
|
||||
throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException());
|
||||
}
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
deviceGroup.setDateOfLastUpdate(new Date().getTime());
|
||||
this.groupDAO.updateGroup(deviceGroup, oldGroupName, oldOwner, tenantId);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
DeviceGroup existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
|
||||
if (existingGroup == null || existingGroup.getGroupId() == groupId) {
|
||||
deviceGroup.setDateOfLastUpdate(new Date().getTime());
|
||||
this.groupDAO.updateGroup(deviceGroup, groupId, tenantId);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
} else {
|
||||
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
|
||||
}
|
||||
} catch (GroupManagementDAOException e) {
|
||||
GroupManagementDAOFactory.rollbackTransaction();
|
||||
throw new GroupManagementException("Error occurred while modifying deviceGroup " +
|
||||
@ -123,13 +138,13 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteGroup(String groupName, String owner) throws GroupManagementException {
|
||||
public boolean deleteGroup(int groupId) throws GroupManagementException {
|
||||
String roleName;
|
||||
DeviceGroupBuilder deviceGroup = getGroupBuilder(groupName, owner);
|
||||
DeviceGroup deviceGroup = getGroup(groupId);
|
||||
if (deviceGroup == null) {
|
||||
return false;
|
||||
}
|
||||
List<String> groupRoles = getRoles(groupName, owner);
|
||||
List<String> groupRoles = getRoles(groupId);
|
||||
for (String role : groupRoles) {
|
||||
if (role != null) {
|
||||
roleName = role.replace("Internal/group-" + deviceGroup.getGroupId() + "-", "");
|
||||
@ -138,7 +153,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
}
|
||||
try {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
this.groupDAO.deleteGroup(groupName, owner, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
this.groupDAO.deleteGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("DeviceGroup " + deviceGroup.getName() + " removed.");
|
||||
@ -146,8 +161,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
return true;
|
||||
} catch (GroupManagementDAOException e) {
|
||||
GroupManagementDAOFactory.rollbackTransaction();
|
||||
throw new GroupManagementException("Error occurred while removing group " +
|
||||
"'" + groupName + "' data.", e);
|
||||
throw new GroupManagementException("Error occurred while removing group data.", e);
|
||||
} catch (TransactionManagementException e) {
|
||||
throw new GroupManagementException("Error occurred while initiating transaction.", e);
|
||||
} finally {
|
||||
@ -159,37 +173,11 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public DeviceGroup getGroup(String groupName, String owner) throws GroupManagementException {
|
||||
return getGroupBuilder(groupName, owner).getGroup();
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
private DeviceGroupBuilder getGroupBuilder(String groupName, String owner) throws GroupManagementException {
|
||||
DeviceGroupBuilder deviceGroupBuilder;
|
||||
public DeviceGroup getGroup(int groupId) throws GroupManagementException {
|
||||
DeviceGroup deviceGroup;
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
deviceGroupBuilder = this.groupDAO.getGroup(groupName, owner, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while obtaining group '" + groupName + "'", e);
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
if (deviceGroupBuilder != null) {
|
||||
deviceGroupBuilder.setUsers(this.getUsers(deviceGroupBuilder.getGroupId()));
|
||||
deviceGroupBuilder.setRoles(this.getRoles(deviceGroupBuilder.getGroupId()));
|
||||
}
|
||||
return deviceGroupBuilder;
|
||||
}
|
||||
|
||||
|
||||
private DeviceGroupBuilder getGroupBuilder(int groupId) throws GroupManagementException {
|
||||
DeviceGroupBuilder groupBroker;
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
groupBroker = this.groupDAO.getGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
deviceGroup = this.groupDAO.getGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while obtaining group '" + groupId + "'", e);
|
||||
} catch (SQLException e) {
|
||||
@ -197,59 +185,16 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
if (groupBroker != null) {
|
||||
groupBroker.setUsers(this.getUsers(groupBroker.getGroupId()));
|
||||
groupBroker.setRoles(this.getRoles(groupBroker.getGroupId()));
|
||||
}
|
||||
return groupBroker;
|
||||
return deviceGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public DeviceGroup getGroup(int groupId) throws GroupManagementException {
|
||||
DeviceGroupBuilder groupBroker = this.getGroupBuilder(groupId);
|
||||
if (groupBroker != null) {
|
||||
groupBroker.setUsers(this.getUsers(groupBroker.getGroupId()));
|
||||
groupBroker.setRoles(this.getRoles(groupBroker.getGroupId()));
|
||||
}
|
||||
return groupBroker.getGroup();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceGroup> findInGroups(String groupName, String owner) throws GroupManagementException {
|
||||
List<DeviceGroupBuilder> deviceGroups = new ArrayList<>();
|
||||
public List<DeviceGroup> getGroups() throws GroupManagementException {
|
||||
List<DeviceGroup> deviceGroups = new ArrayList<>();
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
deviceGroups = this.groupDAO.findInGroups(groupName, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while finding group " + groupName, e);
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
List<DeviceGroup> groupsWithData = new ArrayList<>();
|
||||
for (DeviceGroupBuilder groupBroker : deviceGroups) {
|
||||
groupBroker.setUsers(this.getUsers(groupBroker.getGroupId()));
|
||||
groupBroker.setRoles(this.getRoles(groupBroker.getGroupId()));
|
||||
groupsWithData.add(groupBroker.getGroup());
|
||||
}
|
||||
return groupsWithData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult getGroups(int startIndex, int rowCount) throws GroupManagementException {
|
||||
List<DeviceGroupBuilder> deviceGroups = new ArrayList<>();
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
deviceGroups = this.groupDAO.getGroups(startIndex, rowCount, tenantId);
|
||||
deviceGroups = this.groupDAO.getGroups(tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e);
|
||||
} catch (SQLException e) {
|
||||
@ -257,21 +202,37 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
List<DeviceGroup> groupsWithData = new ArrayList<>();
|
||||
for (DeviceGroupBuilder groupBroker : deviceGroups) {
|
||||
groupBroker.setUsers(this.getUsers(groupBroker.getGroupId()));
|
||||
groupBroker.setRoles(this.getRoles(groupBroker.getGroupId()));
|
||||
groupsWithData.add(groupBroker.getGroup());
|
||||
}
|
||||
PaginationResult paginationResult = new PaginationResult();
|
||||
paginationResult.setRecordsTotal(getGroupCount());
|
||||
paginationResult.setData(groupsWithData);
|
||||
paginationResult.setRecordsFiltered(groupsWithData.size());
|
||||
return paginationResult;
|
||||
return deviceGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult getGroups(String username, int startIndex, int rowCount) throws GroupManagementException {
|
||||
public PaginationResult getGroups(GroupPaginationRequest request) throws GroupManagementException {
|
||||
request = DeviceManagerUtil.validateGroupListPageSize(request);
|
||||
List<DeviceGroup> deviceGroups = getPlainDeviceGroups(request);
|
||||
PaginationResult groupResult = new PaginationResult();
|
||||
groupResult.setData(deviceGroups);
|
||||
groupResult.setRecordsTotal(getGroupCount(request));
|
||||
return groupResult;
|
||||
}
|
||||
|
||||
private List<DeviceGroup> getPlainDeviceGroups(GroupPaginationRequest request) throws GroupManagementException {
|
||||
List<DeviceGroup> deviceGroups = new ArrayList<>();
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
deviceGroups = this.groupDAO.getGroups(request, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e);
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return deviceGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceGroup> getGroups(String username) throws GroupManagementException {
|
||||
Map<Integer, DeviceGroup> groups = new HashMap<>();
|
||||
UserStoreManager userStoreManager;
|
||||
try {
|
||||
@ -279,23 +240,58 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||
.getUserStoreManager();
|
||||
String[] roleList = userStoreManager.getRoleListOfUser(username);
|
||||
int index = 0;
|
||||
for (String role : roleList) {
|
||||
if (role != null && role.contains("Internal/group-")) {
|
||||
DeviceGroupBuilder deviceGroupBuilder = extractNewGroupFromRole(groups, role);
|
||||
if (deviceGroupBuilder != null && startIndex <= index++ && index <= rowCount) {
|
||||
groups.put(deviceGroupBuilder.getGroupId(), deviceGroupBuilder.getGroup());
|
||||
DeviceGroup deviceGroup = checkAndExtractNonExistingGroup(groups, role);
|
||||
if (deviceGroup != null) {
|
||||
groups.put(deviceGroup.getGroupId(), deviceGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (UserStoreException e) {
|
||||
throw new GroupManagementException("Error occurred while getting user store manager.", e);
|
||||
}
|
||||
PaginationResult paginationResult = new PaginationResult();
|
||||
paginationResult.setRecordsTotal(getGroupCount());
|
||||
paginationResult.setData(new ArrayList<>(groups.values()));
|
||||
paginationResult.setRecordsFiltered(groups.size());
|
||||
return paginationResult;
|
||||
return new ArrayList<>(groups.values());
|
||||
}
|
||||
|
||||
public PaginationResult getGroups(String currentUser, GroupPaginationRequest request) throws GroupManagementException {
|
||||
request = DeviceManagerUtil.validateGroupListPageSize(request);
|
||||
int startIndex = request.getStartIndex();
|
||||
int count = request.getRowCount();
|
||||
int index = 0;
|
||||
request.setRowCount(0);
|
||||
List<DeviceGroup> allMatchingGroups = this.getPlainDeviceGroups(request);
|
||||
List<DeviceGroup> deviceGroups = new ArrayList<>();
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
UserStoreManager userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||
.getUserStoreManager();
|
||||
String[] roleList = userStoreManager.getRoleListOfUser(currentUser);
|
||||
List<Integer> groupIds = new ArrayList<>();
|
||||
for (String role : roleList) {
|
||||
if (role != null && role.contains("Internal/group-")) {
|
||||
int groupId = Integer.parseInt(role.split("-")[1]);
|
||||
if (!groupIds.contains(groupId)) {
|
||||
groupIds.add(groupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (DeviceGroup group : allMatchingGroups) {
|
||||
int groupId = group.getGroupId();
|
||||
if (groupIds.contains(groupId)) {
|
||||
if (startIndex <= index && index < count) {
|
||||
deviceGroups.add(group);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
} catch (UserStoreException e) {
|
||||
throw new GroupManagementException("Error occurred while getting user store manager.", e);
|
||||
}
|
||||
PaginationResult groupResult = new PaginationResult();
|
||||
groupResult.setData(deviceGroups);
|
||||
groupResult.setRecordsTotal(index);
|
||||
return groupResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -313,29 +309,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceGroup> getGroups(String username) throws GroupManagementException {
|
||||
UserStoreManager userStoreManager;
|
||||
private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException {
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||
.getUserStoreManager();
|
||||
String[] roleList = userStoreManager.getRoleListOfUser(username);
|
||||
Map<Integer, DeviceGroup> groups = new HashMap<>();
|
||||
for (String role : roleList) {
|
||||
if (role != null && role.contains("Internal/group-")) {
|
||||
DeviceGroupBuilder deviceGroupBuilder = extractNewGroupFromRole(groups, role);
|
||||
if (deviceGroupBuilder != null) {
|
||||
groups.put(deviceGroupBuilder.getGroupId(), deviceGroupBuilder.getGroup());
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(groups.values());
|
||||
} catch (UserStoreException e) {
|
||||
throw new GroupManagementException("Error occurred while getting user store manager.", e);
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return groupDAO.getGroupCount(request, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e);
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,75 +355,57 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean shareGroup(String username, String groupName, String owner, String sharingRole)
|
||||
throws GroupManagementException, UserDoesNotExistException {
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
return modifyGroupShare(username, groupId, sharingRole, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean unshareGroup(String username, String groupName, String owner, String sharingRole)
|
||||
throws GroupManagementException, UserDoesNotExistException {
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
return modifyGroupShare(username, groupId, sharingRole, false);
|
||||
}
|
||||
|
||||
private boolean modifyGroupShare(String username, int groupId, String sharingRole,
|
||||
boolean isAddNew)
|
||||
throws GroupManagementException, UserDoesNotExistException {
|
||||
if (groupId == -1) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void manageGroupSharing(int groupId, String username, List<String> newRoles)
|
||||
throws GroupManagementException, UserDoesNotExistException, RoleDoesNotExistException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
UserStoreManager userStoreManager;
|
||||
String[] roles = new String[1];
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
userStoreManager =
|
||||
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
|
||||
tenantId).getUserStoreManager();
|
||||
if (!userStoreManager.isExistingUser(username)) {
|
||||
throw new UserDoesNotExistException("User not exists with name " + username);
|
||||
}
|
||||
roles[0] = "Internal/group-" + groupId + "-" + sharingRole;
|
||||
List<String> currentRoles = getRoles(username, groupId);
|
||||
if (isAddNew && !currentRoles.contains(sharingRole)) {
|
||||
userStoreManager.updateRoleListOfUser(username, null, roles);
|
||||
} else if (!isAddNew && currentRoles.contains(sharingRole)) {
|
||||
userStoreManager.updateRoleListOfUser(username, roles, null);
|
||||
List<String> currentGroupRoles = getRoles(groupId);
|
||||
List<String> currentUserRoles = getRoles(username, groupId);
|
||||
List<String> rolesToAdd = new ArrayList<>();
|
||||
List<String> rolesToRemove = new ArrayList<>();
|
||||
String roleNamePrefix = "Internal/group-" + groupId + "-";
|
||||
for (String role : newRoles) {
|
||||
if (currentGroupRoles.contains(role)) {
|
||||
if (!currentUserRoles.contains(role)) {
|
||||
rolesToAdd.add(roleNamePrefix + role);
|
||||
}
|
||||
} else {
|
||||
throw new RoleDoesNotExistException("Role '" + role + "' is not exists in requested group.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
for (String role : currentUserRoles) {
|
||||
if (currentGroupRoles.contains(role)) {
|
||||
if (!newRoles.contains(role)) {
|
||||
rolesToRemove.add(roleNamePrefix + role);
|
||||
}
|
||||
} else {
|
||||
throw new RoleDoesNotExistException("Role '" + role + "' is not exists in requested group.");
|
||||
}
|
||||
}
|
||||
userStoreManager.updateRoleListOfUser(username,
|
||||
rolesToRemove.toArray(new String[rolesToRemove.size()]),
|
||||
rolesToAdd.toArray(new String[rolesToAdd.size()]));
|
||||
} catch (UserStoreException e) {
|
||||
if (e instanceof UserDoesNotExistException) {
|
||||
throw (UserDoesNotExistException) e;
|
||||
}
|
||||
throw new GroupManagementException("User store error in adding user " + username + " to group name:" +
|
||||
groupId, e);
|
||||
throw new GroupManagementException("User store error in updating sharing roles.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private int getGroupId(String groupName, String owner) throws GroupManagementException {
|
||||
DeviceGroupBuilder deviceGroupBuilder = getGroupBuilder(groupName, owner);
|
||||
if (deviceGroupBuilder == null) {
|
||||
return -1;
|
||||
}
|
||||
return deviceGroupBuilder.getGroupId();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean addGroupSharingRole(String userName, String groupName, String owner, String roleName,
|
||||
String[] permissions) throws GroupManagementException {
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
return addGroupSharingRole(userName, groupId, roleName, permissions);
|
||||
}
|
||||
|
||||
private boolean addGroupSharingRole(String username, int groupId, String roleName,
|
||||
String[] permissions)
|
||||
public boolean addGroupSharingRole(String username, int groupId, String roleName, String[] permissions)
|
||||
throws GroupManagementException {
|
||||
if (groupId == -1) {
|
||||
return false;
|
||||
@ -469,14 +435,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean removeGroupSharingRole(String groupName, String owner, String roleName)
|
||||
throws GroupManagementException {
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
return removeGroupSharingRole(groupId, roleName);
|
||||
}
|
||||
|
||||
private boolean removeGroupSharingRole(int groupId, String roleName)
|
||||
throws GroupManagementException {
|
||||
public boolean removeGroupSharingRole(int groupId, String roleName) throws GroupManagementException {
|
||||
if (groupId == -1) {
|
||||
return false;
|
||||
}
|
||||
@ -500,12 +459,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<String> getRoles(String groupName, String owner) throws GroupManagementException {
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
return getRoles(groupId);
|
||||
}
|
||||
|
||||
private List<String> getRoles(int groupId) throws GroupManagementException {
|
||||
public List<String> getRoles(int groupId) throws GroupManagementException {
|
||||
UserStoreManager userStoreManager;
|
||||
String[] roles;
|
||||
List<String> groupRoles;
|
||||
@ -532,13 +486,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<String> getRoles(String username, String groupName, String owner)
|
||||
throws GroupManagementException, UserDoesNotExistException {
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
return getRoles(username, groupId);
|
||||
}
|
||||
|
||||
private List<String> getRoles(String username, int groupId)
|
||||
public List<String> getRoles(String username, int groupId)
|
||||
throws GroupManagementException, UserDoesNotExistException {
|
||||
UserStoreManager userStoreManager;
|
||||
List<String> groupRoleList = new ArrayList<>();
|
||||
@ -569,11 +517,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<GroupUser> getUsers(String groupName, String owner) throws GroupManagementException {
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
return getUsers(groupId);
|
||||
}
|
||||
|
||||
public List<GroupUser> getUsers(int groupId) throws GroupManagementException {
|
||||
UserStoreManager userStoreManager;
|
||||
Map<String, GroupUser> groupUserHashMap = new HashMap<>();
|
||||
@ -610,31 +553,13 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<Device> getDevices(String groupName, String owner) throws GroupManagementException {
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return this.groupDAO.getDevices(groupName, owner, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PaginationResult getDevices(String groupName, String owner, int startIndex, int rowCount)
|
||||
public List<Device> getDevices(int groupId, int startIndex, int rowCount)
|
||||
throws GroupManagementException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
List<Device> devices;
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
devices = this.groupDAO.getDevices(groupName, owner, startIndex, rowCount, tenantId);
|
||||
devices = this.groupDAO.getDevices(groupId, startIndex, rowCount, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
||||
} catch (SQLException e) {
|
||||
@ -642,24 +567,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
PaginationResult paginationResult = new PaginationResult();
|
||||
paginationResult.setRecordsTotal(getDeviceCount(groupName, owner));
|
||||
paginationResult.setData(devices);
|
||||
paginationResult.setRecordsFiltered(devices.size());
|
||||
return paginationResult;
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getDeviceCount(String groupName, String owner) throws GroupManagementException {
|
||||
public int getDeviceCount(int groupId) throws GroupManagementException {
|
||||
try {
|
||||
int count;
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
count = groupDAO.getDeviceCount(groupName, owner,
|
||||
CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
return count;
|
||||
return groupDAO.getDeviceCount(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
} catch (GroupManagementDAOException e) {
|
||||
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e);
|
||||
} catch (SQLException e) {
|
||||
@ -673,46 +591,51 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean addDevice(DeviceIdentifier deviceIdentifier, String groupName, String owner)
|
||||
throws GroupManagementException {
|
||||
public void addDevices(int groupId, List<DeviceIdentifier> deviceIdentifiers)
|
||||
throws GroupManagementException, DeviceNotFoundException {
|
||||
Device device;
|
||||
try {
|
||||
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier);
|
||||
if (device == null) {
|
||||
return false;
|
||||
}
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
this.groupDAO.addDevice(groupName, owner, device.getId(), tenantId);
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers){
|
||||
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier);
|
||||
if (device == null) {
|
||||
throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'");
|
||||
}
|
||||
if (!this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId)){
|
||||
this.groupDAO.addDevice(groupId, device.getId(), tenantId);
|
||||
}
|
||||
}
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new GroupManagementException("Error occurred while retrieving device.", e);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
GroupManagementDAOFactory.rollbackTransaction();
|
||||
throw new GroupManagementException("Error occurred while adding device to group '" + groupName + "'.", e);
|
||||
throw new GroupManagementException("Error occurred while adding device to group.", e);
|
||||
} catch (TransactionManagementException e) {
|
||||
throw new GroupManagementException("Error occurred while initiating transaction.", e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean removeDevice(DeviceIdentifier deviceIdentifier, String groupName, String owner)
|
||||
throws GroupManagementException {
|
||||
public void removeDevice(int groupId, List<DeviceIdentifier> deviceIdentifiers)
|
||||
throws GroupManagementException, DeviceNotFoundException {
|
||||
Device device;
|
||||
try {
|
||||
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier);
|
||||
if (device == null) {
|
||||
return false;
|
||||
}
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
this.groupDAO.removeDevice(groupName, owner, device.getId(), tenantId);
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers){
|
||||
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier);
|
||||
if (device == null) {
|
||||
throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'");
|
||||
}
|
||||
this.groupDAO.removeDevice(groupId, device.getId(), tenantId);
|
||||
}
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new GroupManagementException("Error occurred while retrieving device.", e);
|
||||
@ -720,21 +643,19 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
throw new GroupManagementException("Error occurred while initiating transaction.", e);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
GroupManagementDAOFactory.rollbackTransaction();
|
||||
throw new GroupManagementException("Error occurred while adding device to group '" + groupName + "'.", e);
|
||||
throw new GroupManagementException("Error occurred while adding device to group.", e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String[] getPermissions(String username, String groupName, String owner)
|
||||
public String[] getPermissions(String username, int groupId)
|
||||
throws GroupManagementException, UserDoesNotExistException {
|
||||
UserRealm userRealm;
|
||||
int groupId = getGroupId(groupName, owner);
|
||||
List<String> roles = getRoles(username, groupId);
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
@ -774,9 +695,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
for (String role : roles) {
|
||||
if (role != null && role.contains("Internal/group-") && userRealm.getAuthorizationManager()
|
||||
.isRoleAuthorized(role, permission, CarbonConstants.UI_PERMISSION_ACTION)) {
|
||||
DeviceGroupBuilder deviceGroupBuilder = extractNewGroupFromRole(groups, role);
|
||||
if (deviceGroupBuilder != null) {
|
||||
groups.put(deviceGroupBuilder.getGroupId(), deviceGroupBuilder.getGroup());
|
||||
DeviceGroup group = checkAndExtractNonExistingGroup(groups, role);
|
||||
if (group != null) {
|
||||
groups.put(group.getGroupId(), group);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -789,15 +710,11 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
@Override
|
||||
public List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException {
|
||||
DeviceManagementProviderService managementProviderService = new DeviceManagementProviderServiceImpl();
|
||||
List<DeviceGroup> deviceGroups = new ArrayList<>();
|
||||
try {
|
||||
Device device = managementProviderService.getDevice(deviceIdentifier);
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
List<DeviceGroupBuilder> builders = groupDAO.getGroups(device.getId(),
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
for (DeviceGroupBuilder d : builders){
|
||||
deviceGroups.add(d.getGroup());
|
||||
}
|
||||
return groupDAO.getGroups(device.getId(),
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new GroupManagementException("Error occurred while retrieving the device details.", e);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
@ -807,15 +724,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return deviceGroups;
|
||||
}
|
||||
|
||||
private DeviceGroupBuilder extractNewGroupFromRole(Map<Integer, DeviceGroup> groups, String role)
|
||||
/**
|
||||
* This method returns group belongs to particular role, if it is not existed in groups map.
|
||||
*
|
||||
* @param groups existing groups map.
|
||||
* @param role group related role which needs to evaluate.
|
||||
* @return device group if it is not existing in the groups map.
|
||||
* @throws GroupManagementException
|
||||
*/
|
||||
private DeviceGroup checkAndExtractNonExistingGroup(Map<Integer, DeviceGroup> groups, String role)
|
||||
throws GroupManagementException {
|
||||
try {
|
||||
int groupId = Integer.parseInt(role.split("-")[1]);
|
||||
if (!groups.containsKey(groupId)) {
|
||||
return getGroupBuilder(groupId);
|
||||
return getGroup(groupId);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("Unable to extract groupId from role " + role, e);
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
@ -327,6 +328,22 @@ public final class DeviceManagerUtil {
|
||||
return paginationRequest;
|
||||
}
|
||||
|
||||
public static GroupPaginationRequest validateGroupListPageSize(GroupPaginationRequest paginationRequest) throws
|
||||
GroupManagementException {
|
||||
if (paginationRequest.getRowCount() == 0) {
|
||||
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance()
|
||||
.getDeviceManagementConfig();
|
||||
if (deviceManagementConfig != null) {
|
||||
paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration()
|
||||
.getDeviceListPageSize());
|
||||
} else {
|
||||
throw new GroupManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
||||
"cdm-config.xml file.");
|
||||
}
|
||||
}
|
||||
return paginationRequest;
|
||||
}
|
||||
|
||||
public static int validateDeviceListPageSize(int limit) throws DeviceManagementException {
|
||||
if (limit == 0) {
|
||||
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
||||
|
||||
@ -31,7 +31,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.TestUtils;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@ -20,7 +20,6 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.DeviceGroupBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
@ -82,7 +81,6 @@ public class TestDataHolder {
|
||||
deviceGroup.setDateOfCreation(new Date().getTime());
|
||||
deviceGroup.setDateOfLastUpdate(new Date().getTime());
|
||||
deviceGroup.setOwner(OWNER);
|
||||
DeviceGroupBuilder broker = new DeviceGroupBuilder(deviceGroup);
|
||||
return broker.getGroup();
|
||||
return deviceGroup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,14 +24,11 @@ import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.DeviceGroupBuilder;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupDAO;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
@ -40,7 +37,7 @@ import java.util.List;
|
||||
public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GroupPersistTests.class);
|
||||
int groupId = -1;
|
||||
private int groupId = -1;
|
||||
private GroupDAO groupDAO;
|
||||
|
||||
@BeforeClass
|
||||
@ -57,7 +54,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
groupId = groupDAO.addGroup(deviceGroup, TestDataHolder.SUPER_TENANT_ID);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
log.debug("Group added to database.");
|
||||
log.debug("Group added to database. ID: " + groupId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
GroupManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while adding device type '" + deviceGroup.getName() + "'.";
|
||||
@ -76,32 +73,14 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
log.debug("Group name: " + group.getName());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testAddGroupTest"})
|
||||
public void findGroupTest() {
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
List<DeviceGroupBuilder> groups = groupDAO.findInGroups("Test", TestDataHolder.SUPER_TENANT_ID);
|
||||
Assert.assertNotEquals(groups.size(), 0, "No groups found");
|
||||
Assert.assertNotNull(groups.get(0), "Group is null");
|
||||
log.debug("Group found: " + groups.get(0).getName());
|
||||
} catch (GroupManagementDAOException e) {
|
||||
String msg = "Error occurred while find group by name.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
GroupManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testAddGroupTest"})
|
||||
public void getGroupTest() {
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
List<DeviceGroupBuilder> groups = groupDAO.getGroups(0, 100, TestDataHolder.SUPER_TENANT_ID);
|
||||
GroupPaginationRequest request = new GroupPaginationRequest(0, 10);
|
||||
request.setGroupName(null);
|
||||
request.setOwner(null);
|
||||
List<DeviceGroup> groups = groupDAO.getGroups(request, TestDataHolder.SUPER_TENANT_ID);
|
||||
Assert.assertNotEquals(groups.size(), 0, "No groups found");
|
||||
Assert.assertNotNull(groups.get(0), "Group is null");
|
||||
log.debug("No of Groups found: " + groups.size());
|
||||
@ -122,10 +101,10 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
public void addDeviceToGroupTest() {
|
||||
Device initialTestDevice = TestDataHolder.initialTestDevice;
|
||||
DeviceGroup deviceGroup = getGroupById(groupId);
|
||||
Assert.assertNotNull(deviceGroup, "Group is null");
|
||||
try {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
groupDAO.addDevice(deviceGroup.getName(), deviceGroup.getOwner(), initialTestDevice.getId(),
|
||||
TestDataHolder.SUPER_TENANT_ID);
|
||||
groupDAO.addDevice(deviceGroup.getGroupId(), initialTestDevice.getId(), TestDataHolder.SUPER_TENANT_ID);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
log.debug("Device added to group.");
|
||||
} catch (GroupManagementDAOException e) {
|
||||
@ -143,8 +122,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
List<Device> groupedDevices = groupDAO.getDevices(deviceGroup.getName(), deviceGroup.getOwner(),
|
||||
TestDataHolder.SUPER_TENANT_ID);
|
||||
List<Device> groupedDevices = groupDAO.getDevices(deviceGroup.getGroupId(), 0, 10, TestDataHolder.SUPER_TENANT_ID);
|
||||
Assert.assertNotEquals(groupedDevices.size(), 0, "No device found");
|
||||
Assert.assertNotNull(groupedDevices.get(0), "Device is null");
|
||||
Assert.assertEquals(groupedDevices.get(0).getId(), initialTestDevice.getId(), "Device ids not matched");
|
||||
@ -165,9 +143,10 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
public void removeDeviceFromGroupTest() {
|
||||
Device initialTestDevice = TestDataHolder.initialTestDevice;
|
||||
DeviceGroup deviceGroup = getGroupById(groupId);
|
||||
Assert.assertNotNull(deviceGroup, "Group is null");
|
||||
try {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
groupDAO.removeDevice(deviceGroup.getName(), deviceGroup.getOwner(), initialTestDevice.getId(), TestDataHolder.SUPER_TENANT_ID);
|
||||
groupDAO.removeDevice(deviceGroup.getGroupId(), initialTestDevice.getId(), TestDataHolder.SUPER_TENANT_ID);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
log.debug("Device added to group.");
|
||||
} catch (GroupManagementDAOException e) {
|
||||
@ -196,8 +175,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
group.setDescription(desc);
|
||||
try {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
groupDAO.updateGroup(group, TestDataHolder.generateDummyGroupData().getName(),
|
||||
TestDataHolder.generateDummyGroupData().getOwner(), TestDataHolder.SUPER_TENANT_ID);
|
||||
groupDAO.updateGroup(group, groupId, TestDataHolder.SUPER_TENANT_ID);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
log.debug("Group updated");
|
||||
} catch (GroupManagementDAOException e) {
|
||||
@ -226,7 +204,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
try {
|
||||
Assert.assertNotNull(group, "Group is null");
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
groupDAO.deleteGroup(group.getName(), group.getOwner(), TestDataHolder.SUPER_TENANT_ID);
|
||||
groupDAO.deleteGroup(group.getGroupId(), TestDataHolder.SUPER_TENANT_ID);
|
||||
GroupManagementDAOFactory.commitTransaction();
|
||||
log.debug("Group deleted");
|
||||
} catch (GroupManagementDAOException e) {
|
||||
@ -245,7 +223,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
||||
Assert.assertNull(group, "Group is not deleted");
|
||||
}
|
||||
|
||||
public DeviceGroup getGroupById(int groupId) {
|
||||
private DeviceGroup getGroupById(int groupId) {
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return groupDAO.getGroup(groupId, TestDataHolder.SUPER_TENANT_ID);
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -28,12 +28,13 @@ var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
if (uriMatcher.match("/{context}/api/operation/paginate")) {
|
||||
var deviceType = request.getParameter("deviceType");
|
||||
var deviceId = request.getParameter("deviceId");
|
||||
var owner = request.getParameter("owner");
|
||||
var index = request.getParameter("start");
|
||||
var length = request.getParameter("length");
|
||||
var search = request.getParameter("search[value]");
|
||||
|
||||
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/devices/" + deviceType + "/" + deviceId + "/operations?offset=" + index + "&limit=" + length;
|
||||
"/devices/" + deviceType + "/" + deviceId + "/operations?owner=" + owner + "&offset=" + index + "&limit=" + length;
|
||||
|
||||
serviceInvokers.XMLHttp.get(
|
||||
restAPIEndpoint,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
"httpsURL" : "%https.ip%",
|
||||
"httpURL" : "%http.ip%",
|
||||
"httpsWebURL" : "%https.ip%",
|
||||
"wssURL" : "%https.ip%",
|
||||
"wssURL" : "https://localhost:9444",
|
||||
"wsURL" : "%http.ip%",
|
||||
"dashboardServerURL" : "%https.ip%",
|
||||
"enrollmentDir": "/emm-web-agent/enrollment",
|
||||
|
||||
@ -118,13 +118,18 @@ deviceModule = function () {
|
||||
if (properties["DEVICE_INFO"]) {
|
||||
var initialDeviceInfoList = parse(properties["DEVICE_INFO"]);
|
||||
var initialDeviceInfo = {};
|
||||
for (var j = 0; j < initialDeviceInfoList.length; j++) {
|
||||
if (initialDeviceInfoList[j]["value"]) {
|
||||
initialDeviceInfo[initialDeviceInfoList[j]["name"]] =
|
||||
initialDeviceInfoList[j]["value"];
|
||||
if (Array.isArray(initialDeviceInfoList)) {
|
||||
for (var j = 0; j < initialDeviceInfoList.length; j++) {
|
||||
if (initialDeviceInfoList[j]["value"]) {
|
||||
initialDeviceInfo[initialDeviceInfoList[j]["name"]] =
|
||||
initialDeviceInfoList[j]["value"];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
initialDeviceInfo = initialDeviceInfoList;
|
||||
}
|
||||
|
||||
|
||||
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"] = initialDeviceInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,8 +26,7 @@ var groupModule = {};
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
var groupServiceEndpoint = devicemgtProps["httpsURL"] +
|
||||
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/groups";
|
||||
var deviceServiceEndpoint = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0";
|
||||
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
|
||||
@ -36,29 +35,29 @@ var groupModule = {};
|
||||
groupModule.getGroupCount = function () {
|
||||
var permissions = userModule.getUIPermissions();
|
||||
if (permissions.LIST_ALL_GROUPS) {
|
||||
endPoint = groupServiceEndpoint + "/count";
|
||||
endPoint = deviceServiceEndpoint + "/admin/groups/count";
|
||||
} else if (permissions.LIST_GROUPS) {
|
||||
endPoint = groupServiceEndpoint + "/user/" + user.username + "/count";
|
||||
endPoint = deviceServiceEndpoint + "/groups/count";
|
||||
} else {
|
||||
log.error("Access denied for user: " + carbonUser.username);
|
||||
return -1;
|
||||
}
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
endPoint, function (responsePayload) {
|
||||
return responsePayload;
|
||||
return responsePayload["responseText"];
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
log.error(responsePayload["responseText"]);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
groupModule.getGroupDeviceCount = function (groupName, owner) {
|
||||
endPoint = groupServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices/count";
|
||||
groupModule.getGroupDeviceCount = function (groupId) {
|
||||
endPoint = deviceServiceEndpoint + "/groups/id/" + groupId + "/devices/count";
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
endPoint, function (responsePayload) {
|
||||
return responsePayload;
|
||||
return responsePayload["responseText"];
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
@ -67,8 +66,8 @@ var groupModule = {};
|
||||
);
|
||||
};
|
||||
|
||||
groupModule.getGroupDevices = function (groupName, owner) {
|
||||
endPoint = groupServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices";
|
||||
groupModule.getGroupDevices = function (groupId) {
|
||||
endPoint = deviceServiceEndpoint + "/groups/id/" + groupId + "/devices?limit=10";
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
endPoint, function (responsePayload) {
|
||||
return responsePayload;
|
||||
|
||||
@ -485,10 +485,10 @@ var userModule = function () {
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||
permissions["LIST_OWN_DEVICES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/list")) {
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/view")) {
|
||||
permissions["LIST_ALL_GROUPS"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/groups/list")) {
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/view")) {
|
||||
permissions["LIST_GROUPS"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/list")) {
|
||||
|
||||
@ -51,14 +51,6 @@
|
||||
<div id="certificate-create-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label ">
|
||||
Serial Number *
|
||||
</label>
|
||||
<br>
|
||||
<div id="serialNoInputField" class="form-group wr-input-control">
|
||||
<input type="text" id="serialNo" class="form-control"/>
|
||||
</div>
|
||||
<label class="wr-input-label">Certificate *</label>
|
||||
<div id="certificateField" class="form-group wr-input-control">
|
||||
<input type="file" id="certificate" class="form-control"/>
|
||||
|
||||
@ -92,17 +92,11 @@ $(document).ready(function () {
|
||||
* when a user clicks on "Add Certificate" button.
|
||||
*/
|
||||
$("button#add-certificate-btn").click(function () {
|
||||
var serialNoInput = $("input#serialNo");
|
||||
var serialNo = serialNoInput.val();
|
||||
if (!serialNo) {
|
||||
$(errorMsg).text("Serial Number is a required field. It cannot be empty.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
} else if (!pemContent) {
|
||||
if (!pemContent) {
|
||||
$(errorMsg).text(" .pem file must contains certificate information.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
} else {
|
||||
var addCertificateFormData = {};
|
||||
addCertificateFormData.serial = serialNo;
|
||||
addCertificateFormData.pem = pemContent;
|
||||
var certificateList = [];
|
||||
certificateList.push(addCertificateFormData);
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
under the License.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Add Certificate"}}
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
@ -110,73 +111,6 @@
|
||||
<a href="#">By Serial Number</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-certificate-modal-content" class="hide">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Do you really want to remove this certificate ?</h3>
|
||||
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-certificate-yes-link" class="btn-operations">
|
||||
Remove
|
||||
</a>
|
||||
<a href="#" id="remove-certificate-cancel-link" class="btn-operations btn-default">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-certificate-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Done. Certificate was successfully removed.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-certificate-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">An unexpected error occurred. Please try again later.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="errorCertificateView" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-error fw-stack-1x"></i>
|
||||
</span>
|
||||
Unauthorized action!
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
|
||||
@ -54,8 +54,11 @@ function hidePopup() {
|
||||
*/
|
||||
function removeCertificate(serialNumber) {
|
||||
var serviceUrl = base_api_url + "/admin/certificates/" + serialNumber;
|
||||
$(modalPopupContent).html($('#remove-certificate-modal-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('Do you really want to remove this certificate ?');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-certificate-yes-link" class="btn-operations">' +
|
||||
'Remove</a><a href="#" id="remove-certificate-cancel-link" class="btn-operations btn-default">Cancel</a>' +
|
||||
'</div>');
|
||||
modalDialog.show();
|
||||
|
||||
$("a#remove-certificate-yes-link").click(function () {
|
||||
invokerUtil.delete(
|
||||
@ -63,23 +66,29 @@ function removeCertificate(serialNumber) {
|
||||
function () {
|
||||
$("#" + serialNumber).remove();
|
||||
var newCertificateListCount = $(".user-list > span").length;
|
||||
$("#certificate-listing-status-msg").text("Total number of Certificates found : " + newCertificateListCount);
|
||||
$(modalPopupContent).html($('#remove-certificate-success-content').html());
|
||||
$("#certificate-listing-status-msg").text("Total number of Certificates found : " +
|
||||
newCertificateListCount);
|
||||
modalDialog.header('Done. Certificate was successfully removed.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-certificate-success-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
$("a#remove-certificate-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
},
|
||||
function () {
|
||||
$(modalPopupContent).html($('#remove-certificate-error-content').html());
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-certificate-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#remove-certificate-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("a#remove-certificate-cancel-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
|
||||
@ -103,8 +112,9 @@ function InitiateViewOption() {
|
||||
if ($("#can-view").val()) {
|
||||
$(location).attr('href', $(this).data("url"));
|
||||
} else {
|
||||
$(modalPopupContent).html($('#errorCertificateView').html());
|
||||
showPopup();
|
||||
modalDialog.header('Unauthorized action!');
|
||||
modalDialog.content('You do not have permission to view this certificate.');
|
||||
modalDialog.showAsAWarning();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -36,9 +36,7 @@ function onRequest() {
|
||||
viewModel.permissions = permissions;
|
||||
viewModel.enrollmentURL = devicemgtProps.enrollmentURL;
|
||||
viewModel.deviceCount = deviceModule.getDevicesCount();
|
||||
//TODO: Enable Group Management Service API on CDMF
|
||||
//page.group_count = groupModule.getGroupCount();
|
||||
viewModel.groupCount = -1;
|
||||
viewModel.groupCount = groupModule.getGroupCount();
|
||||
viewModel.userCount = userModule.getUsersCount();
|
||||
viewModel.policyCount = policyModule.getPoliciesCount();
|
||||
viewModel.roleCount = userModule.getRolesCount();
|
||||
|
||||
@ -22,7 +22,7 @@ function onRequest(context) {
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
|
||||
var groupName = request.getParameter("groupName");
|
||||
var groupOwner = request.getParameter("groupOwner");
|
||||
var groupId = request.getParameter("groupId");
|
||||
|
||||
var viewModel = {};
|
||||
var title = "Devices";
|
||||
@ -41,9 +41,9 @@ function onRequest(context) {
|
||||
}
|
||||
viewModel.currentUser = currentUser;
|
||||
var deviceCount = 0;
|
||||
if (groupName && groupOwner) {
|
||||
if (groupId) {
|
||||
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
|
||||
deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner);
|
||||
deviceCount = groupModule.getGroupDeviceCount(groupId);
|
||||
} else {
|
||||
deviceCount = deviceModule.getDevicesCount();
|
||||
}
|
||||
|
||||
@ -573,9 +573,9 @@ function attachDeviceEvents() {
|
||||
showPopup();
|
||||
|
||||
var serviceURL;
|
||||
if (permissionsUtil.hasPermission("LIST_ALL_GROUPS")) {
|
||||
serviceURL = "/api/device-mgt/v1.0/groups/all";
|
||||
} else if (permissionsUtil.hasPermission("LIST_GROUPS")) {
|
||||
if ($.hasPermission("LIST_ALL_GROUPS")) {
|
||||
serviceURL = "/api/device-mgt/v1.0/groups";
|
||||
} else if ($.hasPermission("LIST_GROUPS")) {
|
||||
//Get authenticated users groups
|
||||
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all";
|
||||
}
|
||||
@ -583,18 +583,18 @@ function attachDeviceEvents() {
|
||||
invokerUtil.get(serviceURL, function (data) {
|
||||
var groups = JSON.parse(data);
|
||||
var str = '<br /><select id="assign-group-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
||||
for (var i = 0; i < groups.length; i++) {
|
||||
str += '<option value="' + groups[i].owner + "/name/" + groups[i].name + '">' +
|
||||
groups[i].name + '</option>';
|
||||
for (var i = 0; i < groups.deviceGroups.length; i++) {
|
||||
str += '<option value="' + groups.deviceGroups[i].id + '">' +
|
||||
groups.deviceGroups[i].name + '</option>';
|
||||
}
|
||||
str += '</select>';
|
||||
$('#user-groups').html(str);
|
||||
$("a#group-device-yes-link").show();
|
||||
$("a#group-device-yes-link").click(function () {
|
||||
var selectedGroup = $('#assign-group-selector').val();
|
||||
serviceURL = "/api/device-mgt/v1.0/groups/owner/" + selectedGroup + "/devices";
|
||||
var device = {"id": deviceId, "type": deviceType};
|
||||
invokerUtil.post(serviceURL, device, function (data) {
|
||||
serviceURL = "/api/device-mgt/v1.0/groups/id/" + selectedGroup + "/devices";
|
||||
var deviceIdentifiers = [{"id":deviceId,"type":deviceType}];
|
||||
invokerUtil.post(serviceURL, deviceIdentifiers, function (data) {
|
||||
$(modalPopupContent).html($('#group-associate-device-200-content').html());
|
||||
setTimeout(function () {
|
||||
hidePopup();
|
||||
|
||||
@ -20,11 +20,16 @@ function onRequest(context) {
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
|
||||
var groupName = context.uriParams.name;
|
||||
var groupOwner = context.uriParams.owner;
|
||||
var devices = groupModule.getGroupDevices(groupName, groupOwner).data;
|
||||
var groupId = context.uriParams.id;
|
||||
var devices = [];
|
||||
var deviceResponse = groupModule.getGroupDevices(groupId).responseText;
|
||||
|
||||
if(deviceResponse != null) {
|
||||
var deviceResponseObj = parse(deviceResponse);
|
||||
devices = deviceResponseObj.devices;
|
||||
}
|
||||
var page = {
|
||||
"groupName": groupName,
|
||||
"groupOwner": groupOwner,
|
||||
"title": groupName + " Analytics"
|
||||
};
|
||||
if (devices) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/group/{owner}/{name}/analytics",
|
||||
"uri": "/group/{name}/{id}/analytics",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Group Management"}}
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
@ -55,22 +56,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="group-error-content" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-md-7 col-centered center-container">
|
||||
<h4 id="error-msg">Unexpected error occurred!</h4>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="group-unexpected-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/group-add.js"}}
|
||||
|
||||
@ -45,9 +45,8 @@ $(function () {
|
||||
} else {
|
||||
var group = {"name": name, "description": description};
|
||||
|
||||
var successCallback = function (jqXHR) {
|
||||
var data = JSON.parse(jqXHR);
|
||||
if (data.status == 201) {
|
||||
var successCallback = function (jqXHR, status, resp) {
|
||||
if (resp.status == 201) {
|
||||
$('.wr-validation-summary strong').text("Group created. You will be redirected to groups");
|
||||
$('.wr-validation-summary').removeClass("hidden");
|
||||
$('.wr-validation-summary strong').removeClass("label-danger");
|
||||
@ -56,11 +55,11 @@ $(function () {
|
||||
window.location = "../groups";
|
||||
}, 1500);
|
||||
} else {
|
||||
displayErrors(data.status);
|
||||
displayErrors(resp.status);
|
||||
}
|
||||
};
|
||||
|
||||
invokerUtil.post("/devicemgt_admin/groups", group,
|
||||
invokerUtil.post("/api/device-mgt/v1.0/groups", group,
|
||||
successCallback, function (message) {
|
||||
displayErrors(message);
|
||||
});
|
||||
@ -71,10 +70,13 @@ $(function () {
|
||||
});
|
||||
|
||||
function displayErrors(message) {
|
||||
showPopup();
|
||||
$('#error-msg').html(message.responseText);
|
||||
$(modalPopupContent).html($('#group-error-content').html());
|
||||
modalDialog.header('Unexpected error occurred!');
|
||||
modalDialog.content('<h4 id="error-msg"></h4>');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="group-unexpected-error-link" class="btn-operations">Ok' +
|
||||
'</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#group-unexpected-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Group Management"}}
|
||||
{{unit "cdmf.unit.ui.content.title" pageHeader="Groups"}}
|
||||
|
||||
{{unit "cdmf.unit.lib.data-table"}}
|
||||
{{unit "cdmf.unit.data-tables-extended"}}
|
||||
{{unit "cdmf.unit.lib.ui-permissions-utility"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
|
||||
@ -22,6 +22,12 @@
|
||||
var groupCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
|
||||
var assetContainer = "#ast-container";
|
||||
|
||||
function InitiateViewOption() {
|
||||
if ($(".select-enable-btn").text() == "Select") {
|
||||
$(location).attr('href', $(this).data("url"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* On Select All Groups button click function.
|
||||
*
|
||||
@ -86,11 +92,11 @@ function loadGroups() {
|
||||
var groupListing = $("#group-listing");
|
||||
var currentUser = groupListing.data("currentUser");
|
||||
var serviceURL;
|
||||
if (permissionsUtil.hasPermission("LIST_ALL_GROUPS")) {
|
||||
serviceURL = "/devicemgt_admin/groups";
|
||||
} else if (permissionsUtil.hasPermission("LIST_GROUPS")) {
|
||||
if ($.hasPermission("LIST_ALL_GROUPS")) {
|
||||
serviceURL = "/api/device-mgt/v1.0/groups";
|
||||
} else if ($.hasPermission("LIST_GROUPS")) {
|
||||
//Get authenticated users groups
|
||||
serviceURL = "/devicemgt_admin/groups/user/" + currentUser;
|
||||
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser;
|
||||
} else {
|
||||
$("#loading-content").remove();
|
||||
$('#device-table').addClass('hidden');
|
||||
@ -99,78 +105,120 @@ function loadGroups() {
|
||||
return;
|
||||
}
|
||||
|
||||
$('#group-grid').datatables_extended ({
|
||||
serverSide: true,
|
||||
processing: false,
|
||||
searching: true,
|
||||
ordering: false,
|
||||
filter: false,
|
||||
pageLength : 16,
|
||||
ajax: { url : '/devicemgt/api/groups', data : {url : serviceURL},
|
||||
dataSrc: function ( json ) {
|
||||
$('#group-grid').removeClass('hidden');
|
||||
var $list = $("#group-listing :input[type='search']");
|
||||
$list.each(function(){
|
||||
$(this).addClass("hidden");
|
||||
});
|
||||
return json.data;
|
||||
var dataFilter = function (data) {
|
||||
data = JSON.parse(data);
|
||||
var objects = [];
|
||||
$(data.deviceGroups).each(function (index) {
|
||||
objects.push({
|
||||
groupId: data.deviceGroups[index].id,
|
||||
name: data.deviceGroups[index].name,
|
||||
description: data.deviceGroups[index].description,
|
||||
owner: data.deviceGroups[index].owner,
|
||||
dateOfCreation: data.deviceGroups[index].dateOfCreation
|
||||
})
|
||||
});
|
||||
var json = {
|
||||
"recordsTotal": data.count,
|
||||
"data": objects
|
||||
}
|
||||
|
||||
return JSON.stringify(json);
|
||||
};
|
||||
|
||||
var columns = [{
|
||||
targets: 0,
|
||||
data: 'id',
|
||||
class: 'remove-padding icon-only content-fill',
|
||||
render: function (data, type, row, meta) {
|
||||
return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
targets: 1,
|
||||
data: 'name',
|
||||
class: 'fade-edge'
|
||||
},
|
||||
{
|
||||
targets: 2,
|
||||
data: 'owner',
|
||||
class: 'fade-edge remove-padding-top',
|
||||
},
|
||||
{
|
||||
targets: 3,
|
||||
data: 'description',
|
||||
class: 'fade-edge remove-padding-top',
|
||||
},
|
||||
{
|
||||
targets: 4,
|
||||
data: 'id',
|
||||
class: 'text-right content-fill text-left-on-grid-view no-wrap',
|
||||
render: function (id, type, row, meta) {
|
||||
var html;
|
||||
html = '<a href="devices?groupId=' + row.groupId + '&groupName=' + row.name + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
|
||||
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>';
|
||||
|
||||
html += '<a href="group/' + row.name + '/' + row.groupId + '/analytics" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
|
||||
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>';
|
||||
|
||||
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-id="' + row.groupId + '" ' +
|
||||
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>';
|
||||
|
||||
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-group-link" data-group-name="' + row.name + '" ' +
|
||||
'data-group-owner="' + row.owner + '" data-group-description="' + row.description + '" data-group-id="'+row.groupId+'"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
||||
'<i class="fw fw-edit fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">Edit</span></a>';
|
||||
|
||||
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-id="' + row.groupId + '" ' +
|
||||
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x"></i>' +
|
||||
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>';
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
columnDefs: [
|
||||
{ targets: 0, data: 'id', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) {
|
||||
return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
|
||||
}},
|
||||
{targets: 1, data: 'name', className: 'fade-edge'},
|
||||
{ targets: 2, data: 'owner', className: 'fade-edge remove-padding-top'},
|
||||
{ targets: 3, data: 'id', className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
|
||||
render: function ( id, type, row, meta ) {
|
||||
var html;
|
||||
html = '<a href="devices?groupName=' + row.name + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
|
||||
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>';
|
||||
}
|
||||
|
||||
html += '<a href="group/' + row.owner + '/' + row.name + '/analytics" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
|
||||
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>';
|
||||
];
|
||||
|
||||
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-name="' + row.name + '" ' +
|
||||
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>';
|
||||
var fnCreatedRow = function (row, data) {
|
||||
$(row).attr('data-type', 'selectable');
|
||||
$(row).attr('data-groupid', data.id);
|
||||
$.each($('td', row), function (colIndex) {
|
||||
switch (colIndex) {
|
||||
case 1:
|
||||
$(this).attr('data-grid-label', "Name");
|
||||
$(this).attr('data-search', data.name);
|
||||
$(this).attr('data-display', data.name);
|
||||
break;
|
||||
case 2:
|
||||
$(this).attr('data-grid-label', "Owner");
|
||||
$(this).attr('data-search', data.owner);
|
||||
$(this).attr('data-display', data.owner);
|
||||
break;
|
||||
case 3:
|
||||
$(this).attr('data-grid-label', "Description");
|
||||
$(this).attr('data-search', data.description);
|
||||
$(this).attr('data-display', data.description);
|
||||
break;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-group-link" data-group-name="' + row.name + '" ' +
|
||||
'data-group-owner="' + row.owner + '" data-group-description="' + row.description + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
||||
'<i class="fw fw-edit fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">Edit</span></a>';
|
||||
|
||||
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-name="' + row.name + '" ' +
|
||||
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x"></i>' +
|
||||
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>';
|
||||
|
||||
return html;
|
||||
}}
|
||||
],
|
||||
"createdRow": function( row, data, dataIndex ) {
|
||||
$(row).attr('data-type', 'selectable');
|
||||
$(row).attr('data-groupid', data.id);
|
||||
$.each($('td', row), function (colIndex) {
|
||||
switch(colIndex) {
|
||||
case 1:
|
||||
$(this).attr('data-grid-label', "Name");
|
||||
$(this).attr('data-search', data.name);
|
||||
$(this).attr('data-display', data.name);
|
||||
break;
|
||||
case 2:
|
||||
$(this).attr('data-grid-label', "Owner");
|
||||
$(this).attr('data-search', data.owner);
|
||||
$(this).attr('data-display', data.owner);
|
||||
break;
|
||||
}
|
||||
});
|
||||
},
|
||||
"fnDrawCallback": function( oSettings ) {
|
||||
$('#group-grid').datatables_extended_serverside_paging(
|
||||
null,
|
||||
serviceURL,
|
||||
dataFilter,
|
||||
columns,
|
||||
fnCreatedRow,
|
||||
function (oSettings) {
|
||||
$(".icon .text").res_text(0.2);
|
||||
attachEvents();
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
"placeholder": "Search By Group Name",
|
||||
"searchKey": "name"
|
||||
});
|
||||
$(groupCheckbox).click(function () {
|
||||
addGroupSelectedClass(this);
|
||||
});
|
||||
@ -280,7 +328,7 @@ function attachEvents() {
|
||||
* on Group Management page in WSO2 Device Management Server Console.
|
||||
*/
|
||||
$("a.share-group-link").click(function () {
|
||||
var groupName = $(this).data("group-name");
|
||||
var groupId = $(this).data("group-id");
|
||||
var groupOwner = $(this).data("group-owner");
|
||||
$(modalPopupContent).html($('#share-group-w1-modal-content').html());
|
||||
$("a#share-group-next-link").show();
|
||||
@ -291,7 +339,7 @@ function attachEvents() {
|
||||
$("#user-names").html("Please specify a user other than current user.");
|
||||
$("a#share-group-next-link").hide();
|
||||
} else {
|
||||
getAllRoles(groupName, groupOwner, selectedUser);
|
||||
getAllRoles(groupId, selectedUser);
|
||||
}
|
||||
});
|
||||
$("a#share-group-w1-cancel-link").click(function () {
|
||||
@ -305,7 +353,7 @@ function attachEvents() {
|
||||
* on Group Management page in WSO2 IoT Server Console.
|
||||
*/
|
||||
$("a.remove-group-link").click(function () {
|
||||
var groupName = $(this).data("group-name");
|
||||
var groupId = $(this).data("group-id");
|
||||
var groupOwner = $(this).data("group-owner");
|
||||
|
||||
$(modalPopupContent).html($('#remove-group-modal-content').html());
|
||||
@ -313,7 +361,6 @@ function attachEvents() {
|
||||
|
||||
$("a#remove-group-yes-link").click(function () {
|
||||
var successCallback = function (data, textStatus, xhr) {
|
||||
data = JSON.parse(data);
|
||||
if (xhr.status == 200) {
|
||||
$(modalPopupContent).html($('#remove-group-200-content').html());
|
||||
setTimeout(function () {
|
||||
@ -325,7 +372,7 @@ function attachEvents() {
|
||||
}
|
||||
};
|
||||
|
||||
invokerUtil.delete("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName,
|
||||
invokerUtil.delete("/api/device-mgt/v1.0/groups/id/" + groupId,
|
||||
successCallback, function (message) {
|
||||
displayErrors(message);
|
||||
});
|
||||
@ -343,6 +390,7 @@ function attachEvents() {
|
||||
* on Device Management page in WSO2 MDM Console.
|
||||
*/
|
||||
$("a.edit-group-link").click(function () {
|
||||
var groupId = $(this).data("group-id");
|
||||
var groupName = $(this).data("group-name");
|
||||
var groupOwner = $(this).data("group-owner");
|
||||
var groupDescription = $(this).data("group-description");
|
||||
@ -358,8 +406,8 @@ function attachEvents() {
|
||||
var group = {"name": newGroupName, "description": newGroupDescription, "owner": groupOwner};
|
||||
|
||||
var successCallback = function (data, textStatus, xhr) {
|
||||
data = JSON.parse(data);
|
||||
if (xhr.status == 200) {
|
||||
$(modalPopupContent).html($('#edit-group-200-content').html());
|
||||
setTimeout(function () {
|
||||
hidePopup();
|
||||
location.reload(false);
|
||||
@ -369,7 +417,7 @@ function attachEvents() {
|
||||
}
|
||||
};
|
||||
|
||||
invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, group,
|
||||
invokerUtil.put("/api/device-mgt/v1.0/groups/id/" + groupId, group,
|
||||
successCallback, function (message) {
|
||||
displayErrors(message);
|
||||
});
|
||||
@ -381,15 +429,15 @@ function attachEvents() {
|
||||
});
|
||||
}
|
||||
|
||||
function getAllRoles(groupName, groupOwner, selectedUser) {
|
||||
function getAllRoles(groupId, selectedUser) {
|
||||
$(modalPopupContent).html($('#share-group-w2-modal-content').html());
|
||||
$('#user-roles').html('<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>');
|
||||
$("a#share-group-yes-link").hide();
|
||||
var successCallback = function (data, textStatus, xhr) {
|
||||
data = JSON.parse(data);
|
||||
if (xhr.status == 200) {
|
||||
if (data.length > 0) {
|
||||
generateRoleMap(groupName, groupOwner, selectedUser, data);
|
||||
if (data.roles.length > 0) {
|
||||
generateRoleMap(groupId, selectedUser, data.roles);
|
||||
} else {
|
||||
$('#user-roles').html("There is no any roles for this group.");
|
||||
}
|
||||
@ -398,7 +446,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) {
|
||||
}
|
||||
};
|
||||
|
||||
invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles",
|
||||
invokerUtil.get("/api/device-mgt/v1.0/groups/id/" + groupId + "/roles",
|
||||
successCallback, function (message) {
|
||||
displayErrors(message);
|
||||
});
|
||||
@ -408,11 +456,14 @@ function getAllRoles(groupName, groupOwner, selectedUser) {
|
||||
});
|
||||
}
|
||||
|
||||
function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
|
||||
function generateRoleMap(groupId, selectedUser, allRoles) {
|
||||
var successCallback = function (data, textStatus, xhr) {
|
||||
data = JSON.parse(data);
|
||||
if (xhr.status == 200) {
|
||||
var userRoles = data;
|
||||
var userRoles = [];
|
||||
if(data != "EMPTY") {
|
||||
userRoles = data.roles;
|
||||
}
|
||||
var str = '';
|
||||
|
||||
for (var i = 0; i < allRoles.length; i++) {
|
||||
@ -437,14 +488,14 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
|
||||
roles.push(allRoles[i]);
|
||||
}
|
||||
}
|
||||
updateGroupShare(groupName, groupOwner, selectedUser, roles);
|
||||
updateGroupShare(groupId, selectedUser, roles);
|
||||
});
|
||||
} else {
|
||||
displayErrors(xhr);
|
||||
}
|
||||
};
|
||||
|
||||
invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser,
|
||||
invokerUtil.get("/api/device-mgt/v1.0/groups/id/" + groupId + "/roles?userName=" + selectedUser,
|
||||
successCallback, function (message) {
|
||||
displayErrors(message);
|
||||
});
|
||||
@ -454,7 +505,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateGroupShare(groupName, groupOwner, selectedUser, roles) {
|
||||
function updateGroupShare(groupId, selectedUser, roles) {
|
||||
var successCallback = function (data) {
|
||||
$(modalPopupContent).html($('#share-group-200-content').html());
|
||||
setTimeout(function () {
|
||||
@ -463,8 +514,9 @@ function updateGroupShare(groupName, groupOwner, selectedUser, roles) {
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/user/" + selectedUser + "/share/roles",
|
||||
roles, successCallback, function (message) {
|
||||
var deviceGroupShare = {"username": selectedUser, "groupRoles": roles };
|
||||
invokerUtil.post("/api/device-mgt/v1.0/groups/id/" + groupId + "/share",
|
||||
deviceGroupShare, successCallback, function (message) {
|
||||
displayErrors(message);
|
||||
});
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
|
||||
{{unit "cdmf.unit.data-tables-extended"}}
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style>
|
||||
@ -254,384 +255,6 @@
|
||||
<a href="#">By Status</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-policy-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Do you really want to remove the selected policy(s)?</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-policy-yes-link" class="btn-operations">
|
||||
Remove
|
||||
</a>
|
||||
|
||||
<a href="#" id="remove-policy-cancel-link" class="btn-operations btn-default">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-policy-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Done. Selected policy was successfully removed.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-policy-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-policy-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">An unexpected error occurred. Please try again later.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-policy-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-policy-error-devices" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Cannot Remove Policies.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h4>You cannot remove policies that are already applied to devices. Please deselect
|
||||
them and try
|
||||
again.</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-policy-error-devices" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="publish-policy-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Do you really want to publish the selected policy(s)?</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="publish-policy-yes-link" class="btn-operations">Yes</a>
|
||||
<a href="#" id="publish-policy-cancel-link" class="btn-operations btn-default">No</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="publish-policy-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Done. Selected policy was successfully published.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="publish-policy-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="publish-policy-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">An unexpected error occurred. Please try again later.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="publish-policy-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="unpublish-policy-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Do you really want to unpublish the selected policy(s)?</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="unpublish-policy-yes-link" class="btn-operations">
|
||||
Yes
|
||||
</a>
|
||||
|
||||
<a href="#" id="unpublish-policy-cancel-link" class="btn-operations btn-default">
|
||||
No
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="unpublish-policy-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Done. Selected policy was successfully unpublished.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="unpublish-policy-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="unpublish-policy-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">An unexpected error occurred. Please try again later.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="unpublish-policy-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="save-policy-priorities-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Done. New Policy priorities were successfully updated.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="save-policy-priorities-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="save-policy-priorities-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">An unexpected error occurred. Please try again later.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="save-policy-priorities-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="change-policy-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Do you really want to apply changes to all policies?</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="change-policy-yes-link" class="btn-operations">
|
||||
Yes
|
||||
</a>
|
||||
|
||||
<a href="#" id="change-policy-cancel-link" class="btn-operations btn-default">
|
||||
No
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="change-policy-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Done. Changes applied successfully.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="change-policy-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="change-policy-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">An unexpected error occurred. Please try again later.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="change-policy-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="errorPolicyUnPublish" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-error fw-stack-1x"></i>
|
||||
</span>
|
||||
Operation cannot be performed !
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h4>Please select a policy or a list of policies to unpublish.</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="errorPolicyUnPublishSelection" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-error fw-stack-1x"></i>
|
||||
</span>
|
||||
Operation cannot be performed !
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h4>You cannot select already inactive policies. Please deselect inactive policies
|
||||
and try again.</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="errorPolicyPublishSelection" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-error fw-stack-1x"></i>
|
||||
</span>
|
||||
Operation cannot be performed !
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h4>You cannot select already active policies. Please deselect active policies and
|
||||
try again.</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="errorPolicyPublish" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-error fw-stack-1x"></i>
|
||||
</span>
|
||||
Operation cannot be performed !
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h4>Please select a policy or a list of policies to publish.</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="errorPolicy" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-error fw-stack-1x"></i>
|
||||
</span>
|
||||
Operation cannot be performed !
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h4>Please select a policy or a list of policies to remove.</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
|
||||
@ -154,8 +154,10 @@ $(document).ready(function () {
|
||||
|
||||
$("#appbar-btn-apply-changes").click(function () {
|
||||
var applyPolicyChangesAPI = "/devicemgt_admin/policies/apply-changes";
|
||||
$(modalPopupContent).html($('#change-policy-modal-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('Do you really want to apply changes to all policies?');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="change-policy-yes-link" class="btn-operations">Yes' +
|
||||
'</a><a href="#" id="change-policy-cancel-link" class="btn-operations btn-default">No</a></div>');
|
||||
modalDialog.show();
|
||||
|
||||
$("a#change-policy-yes-link").click(function () {
|
||||
invokerUtil.put(
|
||||
@ -163,26 +165,29 @@ $(document).ready(function () {
|
||||
null,
|
||||
// on success
|
||||
function () {
|
||||
$(modalPopupContent).html($('#change-policy-success-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('Done. Changes applied successfully.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="change-policy-success-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
$("a#change-policy-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
location.reload();
|
||||
});
|
||||
},
|
||||
// on error
|
||||
function () {
|
||||
$(modalPopupContent).html($('#change-policy-error-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="change-policy-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#change-policy-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("a#change-policy-cancel-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
});
|
||||
|
||||
@ -204,19 +209,22 @@ $(document).ready(function () {
|
||||
updatePolicyAPI,
|
||||
newPolicyPriorityList,
|
||||
function () {
|
||||
$(modalPopupContent).html($('#save-policy-priorities-success-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('Done. New Policy priorities were successfully updated.');
|
||||
modalDialog.footer('<a href="#" id="save-policy-priorities-success-link" class="btn-operations">Ok' +
|
||||
'</a>');
|
||||
modalDialog.show();
|
||||
$("a#save-policy-priorities-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
},
|
||||
function () {
|
||||
$("#save-policy-priorities-error-content").find(".message-from-server").html(
|
||||
"Message From Server : " + data["statusText"]);
|
||||
$(modalPopupContent).html($('#save-policy-priorities-error-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.content(html("Message From Server : " + data["statusText"]));
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="save-policy-priorities-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#save-policy-priorities-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
);
|
||||
@ -227,16 +235,27 @@ $(document).ready(function () {
|
||||
var policyList = getSelectedPolicies();
|
||||
var statusList = getSelectedPolicyStates();
|
||||
if (($.inArray('Inactive/Updated', statusList) > -1) || ($.inArray('Inactive', statusList) > -1)) {
|
||||
$(modalPopupContent).html($("#errorPolicyUnPublishSelection").html());
|
||||
showPopup();
|
||||
modalDialog.header('Operation cannot be performed !');
|
||||
modalDialog.content('You cannot select already inactive policies. Please deselect inactive policies and ' +
|
||||
'try again.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:modalDialog.hide()" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsAWarning();
|
||||
} else {
|
||||
var serviceURL = "/devicemgt_admin/policies/inactivate";
|
||||
if (policyList == 0) {
|
||||
$(modalPopupContent).html($("#errorPolicyUnPublish").html());
|
||||
modalDialog.header('Operation cannot be performed !');
|
||||
modalDialog.content('Please select a policy or a list of policies to unpublish.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:modalDialog.hide()" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsAWarning();
|
||||
} else {
|
||||
$(modalPopupContent).html($('#unpublish-policy-modal-content').html());
|
||||
modalDialog.header('Do you really want to unpublish the selected policy(s)?');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="unpublish-policy-yes-link" ' +
|
||||
'class="btn-operations">Yes</a><a href="#" id="unpublish-policy-cancel-link" ' +
|
||||
'class="btn-operations btn-default">No</a></div>');
|
||||
modalDialog.show();
|
||||
}
|
||||
showPopup();
|
||||
|
||||
$("a#unpublish-policy-yes-link").click(function () {
|
||||
invokerUtil.put(
|
||||
@ -244,24 +263,29 @@ $(document).ready(function () {
|
||||
policyList,
|
||||
// on success
|
||||
function () {
|
||||
$(modalPopupContent).html($('#unpublish-policy-success-content').html());
|
||||
modalDialog.header('Done. Selected policy was successfully unpublished.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="unpublish-policy-success-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
$("a#unpublish-policy-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
location.reload();
|
||||
});
|
||||
},
|
||||
// on error
|
||||
function () {
|
||||
$(modalPopupContent).html($('#unpublish-policy-error-content').html());
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="unpublish-policy-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#unpublish-policy-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("a#unpublish-policy-cancel-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -271,16 +295,27 @@ $(document).ready(function () {
|
||||
var policyList = getSelectedPolicies();
|
||||
var statusList = getSelectedPolicyStates();
|
||||
if (($.inArray('Active/Updated', statusList) > -1) || ($.inArray('Active', statusList) > -1)) {
|
||||
$(modalPopupContent).html($("#errorPolicyPublishSelection").html());
|
||||
showPopup();
|
||||
modalDialog.header('Operation cannot be performed !');
|
||||
modalDialog.content('You cannot select already active policies. Please deselect active policies and try ' +
|
||||
'again.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:modalDialog.hide()" class="btn-operations">' +
|
||||
'Ok</a></div>');
|
||||
modalDialog.showAsAWarning();
|
||||
} else {
|
||||
var serviceURL = "/devicemgt_admin/policies/activate";
|
||||
if (policyList == 0) {
|
||||
$(modalPopupContent).html($("#errorPolicyPublish").html());
|
||||
modalDialog.header('Operation cannot be performed !');
|
||||
modalDialog.content('Please select a policy or a list of policies to publish.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:modalDialog.hide()" class="btn-operations">' +
|
||||
'Ok</a></div>');
|
||||
modalDialog.showAsAWarning();
|
||||
} else {
|
||||
$(modalPopupContent).html($('#publish-policy-modal-content').html());
|
||||
modalDialog.header('Do you really want to publish the selected policy(s)?');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="publish-policy-yes-link" ' +
|
||||
'class="btn-operations">Yes</a><a href="#" id="publish-policy-cancel-link" ' +
|
||||
'class="btn-operations btn-default">No</a></div>');
|
||||
modalDialog.show();
|
||||
}
|
||||
showPopup();
|
||||
|
||||
$("a#publish-policy-yes-link").click(function () {
|
||||
invokerUtil.put(
|
||||
@ -288,24 +323,29 @@ $(document).ready(function () {
|
||||
policyList,
|
||||
// on success
|
||||
function () {
|
||||
$(modalPopupContent).html($('#publish-policy-success-content').html());
|
||||
modalDialog.header('Done. Selected policy was successfully published.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="publish-policy-success-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
$("a#publish-policy-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
location.reload();
|
||||
});
|
||||
},
|
||||
// on error
|
||||
function () {
|
||||
$(modalPopupContent).html($('#publish-policy-error-content').html());
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="publish-policy-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#publish-policy-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("a#publish-policy-cancel-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -314,11 +354,18 @@ $(document).ready(function () {
|
||||
var policyList = getSelectedPolicies();
|
||||
var deletePolicyAPI = "/devicemgt_admin/policies/bulk-remove";
|
||||
if (policyList == 0) {
|
||||
$(modalPopupContent).html($("#errorPolicy").html());
|
||||
modalDialog.header('Operation cannot be performed !');
|
||||
modalDialog.content('Please select a policy or a list of policies to remove.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:modalDialog.hide()" class="btn-operations">' +
|
||||
'Ok</a></div>');
|
||||
modalDialog.showAsAWarning();
|
||||
} else {
|
||||
$(modalPopupContent).html($('#remove-policy-modal-content').html());
|
||||
modalDialog.header('Do you really want to remove the selected policy(s)?');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-policy-yes-link" class=' +
|
||||
'"btn-operations">Remove</a> <a href="#" id="remove-policy-cancel-link" ' +
|
||||
'class="btn-operations btn-default">Cancel</a></div>');
|
||||
modalDialog.show();
|
||||
}
|
||||
showPopup();
|
||||
|
||||
$("a#remove-policy-yes-link").click(function () {
|
||||
invokerUtil.post(
|
||||
@ -328,30 +375,41 @@ $(document).ready(function () {
|
||||
function (data) {
|
||||
data = JSON.parse(data);
|
||||
if (data.errorMessage) {
|
||||
$(modalPopupContent).html($('#remove-policy-error-devices').html());
|
||||
modalDialog.header('Cannot Remove Policies.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-policy-error-devices" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#remove-policy-error-devices").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
} else {
|
||||
$(modalPopupContent).html($('#remove-policy-success-content').html());
|
||||
modalDialog.header('Done. Selected policy was successfully removed.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-policy-success-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
$("a#remove-policy-success-link").click(function () {
|
||||
var thisTable = $(".DTTT_selected").closest('.dataTables_wrapper').find('.dataTable').dataTable();
|
||||
thisTable.api().rows('.DTTT_selected').remove().draw(false);
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
},
|
||||
// on error
|
||||
function (data) {
|
||||
if (JSON.parse(data.responseText).errorMessage) {
|
||||
$(modalPopupContent).html($('#remove-policy-error-devices').html());
|
||||
modalDialog.header('Cannot Remove Policies.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-policy-error-devices" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#remove-policy-error-devices").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
} else {
|
||||
$(modalPopupContent).html($('#remove-policy-error-content').html());
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-policy-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#remove-policy-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -359,7 +417,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$("a#remove-policy-cancel-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
});
|
||||
$("#loading-content").remove();
|
||||
|
||||
@ -210,8 +210,10 @@ $("#role-grid").on("click", ".remove-role-link", function () {
|
||||
if (userStore) {
|
||||
removeRoleAPI += "?user-store=" + encodeURIComponent(userStore);
|
||||
}
|
||||
$(modalPopupContent).html($('#remove-role-modal-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('Do you really want to remove this role ?');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-role-yes-link" class="btn-operations">Remove</a>' +
|
||||
'<a href="#" id="remove-role-cancel-link" class="btn-operations btn-default">Cancel</a></div>');
|
||||
modalDialog.show();
|
||||
|
||||
$("a#remove-role-yes-link").click(function () {
|
||||
invokerUtil.delete(
|
||||
@ -221,22 +223,28 @@ $("#role-grid").on("click", ".remove-role-link", function () {
|
||||
role = userStore + '/' + role;
|
||||
}
|
||||
$('[id="role-' + role + '"]').remove();
|
||||
$(modalPopupContent).html($('#remove-role-success-content').html());
|
||||
modalDialog.header('Done. Role was successfully removed.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-role-success-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
$("a#remove-role-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
},
|
||||
function () {
|
||||
$(modalPopupContent).html($('#remove-role-error-content').html());
|
||||
// $(modalPopupContent).html($('#remove-role-error-content').html());
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-role-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#remove-role-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("a#remove-role-cancel-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Role Management"}}
|
||||
{{unit "cdmf.unit.data-tables-extended"}}
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
@ -80,58 +81,6 @@
|
||||
<th>By Role name</th>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="remove-role-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Do you really want to remove this role ?</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-role-yes-link" class="btn-operations">
|
||||
Remove
|
||||
</a>
|
||||
<a href="#" id="remove-role-cancel-link" class="btn-operations btn-default">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-role-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Done. Role was successfully removed.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-role-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-role-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">An unexpected error occurred. Please try again later.</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-role-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
{{#zone "footer"}}
|
||||
<p>
|
||||
<span class="hidden-xs">WSO2 Carbon Device Management Framework v1.1.3</span>
|
||||
<span class="visible-xs-inline">WSO2 CDMF v1.1.3</span> | © <script>document.write(new Date().getFullYear());</script>,
|
||||
<span class="visible-xs-inline">WSO2 CDMF v1.2.6</span> | © <script>document.write(new Date().getFullYear());</script>,
|
||||
<a href="http://wso2.com/" target="_blank"><i class="icon fw fw-wso2"></i> Inc</a>. All Rights Reserved.
|
||||
</p>
|
||||
{{/zone}}
|
||||
@ -16,6 +16,8 @@
|
||||
under the License.
|
||||
}}
|
||||
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
<div class="row wr-device-board">
|
||||
<div class="col-lg-12 wr-secondary-bar">
|
||||
<span class="page-sub-title">
|
||||
@ -88,111 +90,6 @@
|
||||
{{/equal}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="apply-changes-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h3>Do you really want to apply changes to all policies?</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:void(0)" id="apply-changes-yes-link" class="btn-operations">
|
||||
Yes
|
||||
</a>
|
||||
<a href="javascript:void(0)" id="apply-changes-cancel-link" class="btn-operations">
|
||||
No
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="apply-changes-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h3>Done. Changes applied successfully.</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:void(0)" id="apply-changes-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="apply-changes-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h3>An unexpected error occurred. Please try again later.</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:void(0)" id="apply-changes-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-policy-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h3>An unexpected error occurred. Please try again later.</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:void(0)" id="remove-policy-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="save-policy-priorities-success-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h3>Done. New Policy priorities were successfully updated.</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:void(0)" id="save-policy-priorities-success-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="save-policy-priorities-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h3>An unexpected error occurred. Please try again later.</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:void(0)" id="save-policy-priorities-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
|
||||
@ -87,10 +87,12 @@ $(document).ready(function () {
|
||||
// on success
|
||||
function (data, textStatus, jqXHR) {
|
||||
if (jqXHR.status == 200) {
|
||||
$(modalPopupContent).html($('#save-policy-priorities-success-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('Done. New Policy priorities were successfully updated.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:void(0)" ' +
|
||||
'id="save-policy-priorities-success-link" class="btn-operations">Ok</a></div>');
|
||||
modalDialog.show();
|
||||
$("a#save-policy-priorities-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
$(applyChangesBtn).prop("disabled", false);
|
||||
}
|
||||
@ -98,10 +100,12 @@ $(document).ready(function () {
|
||||
// on error
|
||||
function (jqXHR) {
|
||||
if (jqXHR.status == 400 || jqXHR.status == 500) {
|
||||
$(modalPopupContent).html($("#save-policy-priorities-error-content").html());
|
||||
showPopup();
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:void(0)" ' +
|
||||
'id="save-policy-priorities-error-link" class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#save-policy-priorities-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -110,8 +114,11 @@ $(document).ready(function () {
|
||||
|
||||
$(applyChangesBtn).click(function () {
|
||||
var applyPolicyChangesAPI = "/api/device-mgt/v1.0/policies/apply-changes";
|
||||
$(modalPopupContent).html($("#apply-changes-modal-content").html());
|
||||
showPopup();
|
||||
modalDialog.header('Do you really want to apply changes to all policies?');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:void(0)" id="apply-changes-yes-link" ' +
|
||||
'class="btn-operations">Yes</a><a href="javascript:void(0)" id="apply-changes-cancel-link" ' +
|
||||
'class="btn-operations">No</a></div>');
|
||||
modalDialog.show();
|
||||
|
||||
$("a#apply-changes-yes-link").click(function () {
|
||||
invokerUtil.put(
|
||||
@ -120,20 +127,24 @@ $(document).ready(function () {
|
||||
// on success
|
||||
function (data, textStatus, jqXHR) {
|
||||
if (jqXHR.status == 200) {
|
||||
$(modalPopupContent).html($("#apply-changes-success-content").html());
|
||||
showPopup();
|
||||
modalDialog.header('Done. Changes applied successfully.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:void(0)" ' +
|
||||
'id="apply-changes-success-link" class="btn-operations">Ok</a></div>');
|
||||
modalDialog.show();
|
||||
$("a#apply-changes-success-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
},
|
||||
// on error
|
||||
function (jqXHR) {
|
||||
if (jqXHR.status == 500) {
|
||||
$(modalPopupContent).html($("#apply-changes-error-content").html());
|
||||
showPopup();
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="javascript:void(0)" ' +
|
||||
'id="apply-changes-error-link" class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#apply-changes-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -141,7 +152,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$("a#apply-changes-cancel-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -16,6 +16,9 @@
|
||||
under the License.
|
||||
}}
|
||||
<!-- content/body -->
|
||||
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- content -->
|
||||
@ -81,22 +84,6 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="child-deselect-error-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h3>Can't deselect child permissions when parent permission is selected.</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="child-deselect-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -132,10 +132,14 @@ $(document).ready(function () {
|
||||
$("#permissionList li input").click(function(){
|
||||
var parentInput = $(this).parents("ul:eq(1) > li").find('input:eq(0)');
|
||||
if(parentInput && parentInput.is(':checked')){
|
||||
$(modalPopupContent).html($('#child-deselect-error-content').html());
|
||||
showPopup();
|
||||
modalDialog.header('');
|
||||
modalDialog.content('Can\'t deselect child permissions when parent permission is ' +
|
||||
'selected.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="child-deselect-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsAWarning();
|
||||
$("a#child-deselect-error-link").click(function () {
|
||||
hidePopup();
|
||||
modalDialog.hide();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -6506,3 +6506,8 @@ select > option:hover {
|
||||
.label-bold{
|
||||
font-weight:400;
|
||||
}
|
||||
|
||||
/* Adding style for required fields */
|
||||
.required:before {
|
||||
content: "*";
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>email-sender</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<version>1.2.7-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user