forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt into apim
commit
52388ed33d
@ -0,0 +1,209 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.1.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.certificate.mgt.api</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>WSO2 Carbon - Mobile Device Management API</name>
|
||||
<description>WSO2 Carbon - Certificate Management API</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
|
||||
<warName>certificate-mgt</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>deploy</id>
|
||||
<build>
|
||||
<defaultGoal>compile</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<copy todir="${basedir}/../../../repository/deployment/server/webapps"
|
||||
overwrite="true">
|
||||
<fileset dir="${basedir}/target">
|
||||
<include name="certificate-mgt.war"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>client</id>
|
||||
<build>
|
||||
<defaultGoal>test</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec.wso2</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2-client</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.neethi.wso2</groupId>
|
||||
<artifactId>neethi</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-core</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
package org.wso2.carbon.certificate.mgt.jaxrs.api;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public interface CertificateMgtService {
|
||||
|
||||
/**
|
||||
* Sign the client's certificate signing request and save it in the database.
|
||||
*
|
||||
* @param binarySecurityToken Base64 encoded Certificate signing request.
|
||||
* @return X509Certificate type sign certificate.
|
||||
*/
|
||||
@POST
|
||||
@Path("csr-sign")
|
||||
@Produces({MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN})
|
||||
@Consumes({MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN})
|
||||
Response getSignedCertFromCSR(String binarySecurityToken);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.certificate.mgt.jaxrs.api.common;
|
||||
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
|
||||
@Produces({ "application/json", "application/xml" })
|
||||
public class ErrorHandler implements ExceptionMapper<MDMAPIException> {
|
||||
|
||||
public Response toResponse(MDMAPIException exception) {
|
||||
ErrorMessage errorMessage = new ErrorMessage();
|
||||
errorMessage.setErrorMessage(exception.getErrorMessage());
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.certificate.mgt.jaxrs.api.common;
|
||||
|
||||
|
||||
public class ErrorMessage {
|
||||
|
||||
private String errorMessage;
|
||||
private String errorCode;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(String errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.certificate.mgt.jaxrs.api.common;
|
||||
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.ext.MessageBodyReader;
|
||||
import javax.ws.rs.ext.MessageBodyWriter;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
|
||||
@Provider
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Consumes(APPLICATION_JSON)
|
||||
public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, MessageBodyReader<Object> {
|
||||
|
||||
private Gson gson;
|
||||
private static final String UTF_8 = "UTF-8";
|
||||
|
||||
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Gson getGson() {
|
||||
if (gson == null) {
|
||||
final GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gson = gsonBuilder.create();
|
||||
}
|
||||
return gson;
|
||||
}
|
||||
|
||||
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations, MediaType mediaType,
|
||||
MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream entityStream)
|
||||
throws IOException, WebApplicationException {
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8");
|
||||
|
||||
try {
|
||||
return getGson().fromJson(reader, type);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public long getSize(Object o, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void writeTo(Object object, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType,
|
||||
MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream entityStream)
|
||||
throws IOException, WebApplicationException {
|
||||
|
||||
OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8);
|
||||
try {
|
||||
Type jsonType = null;
|
||||
if (type.equals(type)) {
|
||||
jsonType = type;
|
||||
}
|
||||
getGson().toJson(object, jsonType, writer);
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.certificate.mgt.jaxrs.api.common;
|
||||
|
||||
/**
|
||||
* Custom exception class for handling CDM API related exceptions.
|
||||
*/
|
||||
public class MDMAPIException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 7950151650447893900L;
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public MDMAPIException(String msg, Exception e) {
|
||||
super(msg, e);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public MDMAPIException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public MDMAPIException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public MDMAPIException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MDMAPIException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package org.wso2.carbon.certificate.mgt.jaxrs.api.impl;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||
import org.wso2.carbon.certificate.mgt.jaxrs.api.CertificateMgtService;
|
||||
import org.wso2.carbon.certificate.mgt.jaxrs.exception.Message;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
|
||||
public class CertificateMgtServiceImpl implements CertificateMgtService {
|
||||
private static Log log = LogFactory.getLog(CertificateMgtServiceImpl.class);
|
||||
|
||||
@POST
|
||||
@Path("signcsr")
|
||||
@Produces({MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN})
|
||||
@Consumes({MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN})
|
||||
public Response getSignedCertFromCSR(String binarySecurityToken) {
|
||||
Message message = new Message();
|
||||
X509Certificate signedCert;
|
||||
String singedCertificate;
|
||||
Base64 base64 = new Base64();
|
||||
CertificateGenerator certificateGenerator = new CertificateGenerator();
|
||||
try {
|
||||
if (certificateGenerator.getSignedCertificateFromCSR(binarySecurityToken) == null) {
|
||||
message.setErrorMessage("Error occurred while signing the CSR.");
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
|
||||
entity(message).build();
|
||||
} else {
|
||||
signedCert = certificateGenerator.getSignedCertificateFromCSR(binarySecurityToken);
|
||||
singedCertificate = base64.encodeToString(signedCert.getEncoded());
|
||||
return Response.status(Response.Status.OK).entity(singedCertificate).build();
|
||||
}
|
||||
} catch (KeystoreException e) {
|
||||
String msg = "Error occurred while fetching certificate.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (CertificateEncodingException e) {
|
||||
String msg = "Error occurred while encoding the certificate.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.certificate.mgt.jaxrs.api.util;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class ResponsePayload {
|
||||
|
||||
private int statusCode;
|
||||
private String messageFromServer;
|
||||
private Object responseContent;
|
||||
|
||||
@XmlElement
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getMessageFromServer() {
|
||||
return messageFromServer;
|
||||
}
|
||||
|
||||
public void setMessageFromServer(String messageFromServer) {
|
||||
this.messageFromServer = messageFromServer;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Object getResponseContent() {
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
public void setResponseContent(Object responseContent) {
|
||||
this.responseContent = responseContent;
|
||||
}
|
||||
|
||||
private ResponsePayloadBuilder getBuilder() {
|
||||
return new ResponsePayloadBuilder();
|
||||
}
|
||||
|
||||
public static ResponsePayloadBuilder statusCode(int statusCode) {
|
||||
ResponsePayload message = new ResponsePayload();
|
||||
return message.getBuilder().statusCode(statusCode);
|
||||
}
|
||||
|
||||
public static ResponsePayloadBuilder messageFromServer(String messageFromServer) {
|
||||
ResponsePayload message = new ResponsePayload();
|
||||
return message.getBuilder().messageFromServer(messageFromServer);
|
||||
}
|
||||
|
||||
public static ResponsePayloadBuilder responseContent(String responseContent) {
|
||||
ResponsePayload message = new ResponsePayload();
|
||||
return message.getBuilder().responseContent(responseContent);
|
||||
}
|
||||
|
||||
public class ResponsePayloadBuilder {
|
||||
|
||||
private int statusCode;
|
||||
private String messageFromServer;
|
||||
private Object responseContent;
|
||||
|
||||
public ResponsePayloadBuilder statusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponsePayloadBuilder messageFromServer(String messageFromServer) {
|
||||
this.messageFromServer = messageFromServer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponsePayloadBuilder responseContent(String responseContent) {
|
||||
this.responseContent = responseContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponsePayload build() {
|
||||
ResponsePayload payload = new ResponsePayload();
|
||||
payload.setStatusCode(statusCode);
|
||||
payload.setMessageFromServer(messageFromServer);
|
||||
payload.setResponseContent(responseContent);
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.certificate.mgt.jaxrs.exception;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class BadRequestException extends WebApplicationException {
|
||||
|
||||
public BadRequestException(Message message, MediaType mediaType) {
|
||||
super(Response.status(Response.Status.BAD_REQUEST).entity(message).type(mediaType).build());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.certificate.mgt.jaxrs.exception;
|
||||
|
||||
public class Message {
|
||||
|
||||
private String errorMessage;
|
||||
private String discription;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public String getDiscription() {
|
||||
return discription;
|
||||
}
|
||||
|
||||
public void setDiscription(String discription) {
|
||||
this.discription = discription;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<!-- This file contains the list of permissions that are associated with URL end points
|
||||
of the web app. Each permission should contain the name, permission path ,API path
|
||||
(URL) , HTTP method and OAUTH2 authorization scope (not-required).
|
||||
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
|
||||
For ex:
|
||||
Actual API endpoint: devicemgt_admin/1.0.0/devices/{device-id}
|
||||
URL to be represented here: /devices/*
|
||||
NOTE: All the endpoints of the web app should be available in this file. Otherwise
|
||||
it will result 403 error at the runtime.
|
||||
-->
|
||||
<PermissionConfiguration>
|
||||
<APIVersion></APIVersion>
|
||||
<!-- Device related APIs -->
|
||||
<Permission>
|
||||
<name>get certificate in the database</name>
|
||||
<path>/device-mgt/emm-admin/certificate/GetSignCSR</path>
|
||||
<url>/certificates/signcsr</url>
|
||||
<method>POST</method>
|
||||
<scope>emm_admin</scope>
|
||||
</Permission>
|
||||
</PermissionConfiguration>
|
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
||||
-->
|
||||
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
||||
|
||||
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
||||
<ParentFirst>false</ParentFirst>
|
||||
|
||||
<!--
|
||||
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
||||
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
||||
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
||||
-->
|
||||
<Environments>CXF,Carbon</Environments>
|
||||
</Classloading>
|
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||
|
||||
<jaxrs:server id="services" address="/">
|
||||
<jaxrs:serviceBeans>
|
||||
<ref bean="swaggerResource"/>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="jsonProvider"/>
|
||||
<ref bean="errorHandler"/>
|
||||
<ref bean="swaggerWriter"/>
|
||||
</jaxrs:providers>
|
||||
</jaxrs:server>
|
||||
<jaxrs:server id="certificateService" address="/certificates">
|
||||
<jaxrs:serviceBeans>
|
||||
<ref bean="certificateServiceBean"/>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="jsonProvider"/>
|
||||
<ref bean="errorHandler"/>
|
||||
</jaxrs:providers>
|
||||
</jaxrs:server>
|
||||
|
||||
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers"/>
|
||||
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource"/>
|
||||
|
||||
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
|
||||
<property name="resourcePackage" value="org.wso2.carbon.certificate.mgt.jaxrs"/>
|
||||
<property name="version" value="1.0.0"/>
|
||||
<property name="host" value="localhost:9443"/>
|
||||
<property name="basePath" value="/"/>
|
||||
<property name="title" value="Device Management Admin Service API Definitions"/>
|
||||
<property name="contact" value="dev@wso2.org"/>
|
||||
<property name="license" value="Apache 2.0"/>
|
||||
<property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>
|
||||
<property name="scan" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean id="certificateServiceBean" class="org.wso2.carbon.certificate.mgt.jaxrs.api.impl.CertificateMgtServiceImpl"/>
|
||||
<bean id="jsonProvider" class="org.wso2.carbon.certificate.mgt.jaxrs.api.common.GsonMessageBodyHandler"/>
|
||||
<bean id="errorHandler" class="org.wso2.carbon.certificate.mgt.jaxrs.api.common.ErrorHandler"/>
|
||||
|
||||
</beans>
|
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
|
||||
<display-name>Certificate-Webapp</display-name>
|
||||
<servlet>
|
||||
<description>JAX-WS/JAX-RS Certificate Management Endpoint</description>
|
||||
<display-name>JAX-WS/JAX-RS Servlet</display-name>
|
||||
<servlet-name>CXFServlet</servlet-name>
|
||||
<servlet-class>
|
||||
org.apache.cxf.transport.servlet.CXFServlet
|
||||
</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>CXFServlet</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<session-config>
|
||||
<session-timeout>60</session-timeout>
|
||||
</session-config>
|
||||
|
||||
<context-param>
|
||||
<param-name>isAdminService</param-name>
|
||||
<param-value>false</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>doAuthentication</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
|
||||
<!--publish to apim-->
|
||||
<context-param>
|
||||
<param-name>managed-api-enabled</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-owner</param-name>
|
||||
<param-value>admin</param-value>
|
||||
</context-param>
|
||||
|
||||
</web-app>
|
11
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/FilterSet.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/BasicFilterSet.java
11
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/FilterSet.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/BasicFilterSet.java
2
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceCountByGroupEntry.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceCountByGroup.java
2
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceCountByGroupEntry.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceCountByGroup.java
2
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DetailedDeviceEntry.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceWithDetails.java
2
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DetailedDeviceEntry.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/bean/DeviceWithDetails.java
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.analytics.dashboard.bean;
|
||||
|
||||
public class ExtendedFilterSet extends BasicFilterSet {
|
||||
|
||||
/*
|
||||
* Following property is an abstract filter, introduced @ service layer,
|
||||
* wrapping few (actual) low level database properties.
|
||||
*/
|
||||
private String potentialVulnerability;
|
||||
|
||||
public String getPotentialVulnerability() {
|
||||
return potentialVulnerability;
|
||||
}
|
||||
|
||||
public void setPotentialVulnerability(String potentialVulnerability) {
|
||||
this.potentialVulnerability = potentialVulnerability;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.analytics.dashboard.exception;
|
||||
|
||||
/**
|
||||
* Custom exception class for catching invalid parameter values,
|
||||
* relevant to Gadget Data Service DAO layer.
|
||||
*/
|
||||
public class InvalidFeatureCodeValueException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
private static final long serialVersionUID = 2021891706072918864L;
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and nested exception.
|
||||
* @param errorMessage specific error message.
|
||||
* @param nestedException Nested exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidFeatureCodeValueException(String errorMessage, Exception nestedException) {
|
||||
super(errorMessage, nestedException);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and cause.
|
||||
* @param errorMessage Specific error message.
|
||||
* @param cause Cause of this exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidFeatureCodeValueException(String errorMessage, Throwable cause) {
|
||||
super(errorMessage, cause);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message.
|
||||
* @param errorMessage Specific error message.
|
||||
*/
|
||||
public InvalidFeatureCodeValueException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and cause.
|
||||
* @param cause Cause of this exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidFeatureCodeValueException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.analytics.dashboard.exception;
|
||||
|
||||
/**
|
||||
* Custom exception class for catching invalid parameter values,
|
||||
* relevant to Gadget Data Service DAO layer.
|
||||
*/
|
||||
public class InvalidPotentialVulnerabilityValueException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
private static final long serialVersionUID = 2021891706072918864L;
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and nested exception.
|
||||
* @param errorMessage specific error message.
|
||||
* @param nestedException Nested exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidPotentialVulnerabilityValueException(String errorMessage, Exception nestedException) {
|
||||
super(errorMessage, nestedException);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and cause.
|
||||
* @param errorMessage Specific error message.
|
||||
* @param cause Cause of this exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidPotentialVulnerabilityValueException(String errorMessage, Throwable cause) {
|
||||
super(errorMessage, cause);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message.
|
||||
* @param errorMessage Specific error message.
|
||||
*/
|
||||
public InvalidPotentialVulnerabilityValueException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and cause.
|
||||
* @param cause Cause of this exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidPotentialVulnerabilityValueException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.analytics.dashboard.exception;
|
||||
|
||||
/**
|
||||
* Custom exception class for catching invalid parameter values,
|
||||
* relevant to Gadget Data Service DAO layer.
|
||||
*/
|
||||
public class InvalidResultCountValueException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
private static final long serialVersionUID = 2021891706072918864L;
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and nested exception.
|
||||
* @param errorMessage specific error message.
|
||||
* @param nestedException Nested exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidResultCountValueException(String errorMessage, Exception nestedException) {
|
||||
super(errorMessage, nestedException);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and cause.
|
||||
* @param errorMessage Specific error message.
|
||||
* @param cause Cause of this exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidResultCountValueException(String errorMessage, Throwable cause) {
|
||||
super(errorMessage, cause);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message.
|
||||
* @param errorMessage Specific error message.
|
||||
*/
|
||||
public InvalidResultCountValueException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specific error message and cause.
|
||||
* @param cause Cause of this exception.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public InvalidResultCountValueException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
13
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/InvalidParameterValueException.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/InvalidStartIndexValueException.java
13
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/InvalidParameterValueException.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/exception/InvalidStartIndexValueException.java
@ -0,0 +1,81 @@
|
||||
package org.wso2.carbon.device.mgt.jaxrs.api;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("/dashboard")
|
||||
@Api(value = "Dashboard", description = "Dashboard related operations are described here.")
|
||||
@SuppressWarnings("NonJaxWsWebServices")
|
||||
public interface Dashboard {
|
||||
|
||||
String CONNECTIVITY_STATUS = "connectivity-status";
|
||||
String POTENTIAL_VULNERABILITY = "potential-vulnerability";
|
||||
String NON_COMPLIANT_FEATURE_CODE = "non-compliant-feature-code";
|
||||
String PLATFORM = "platform";
|
||||
String OWNERSHIP = "ownership";
|
||||
// Constants related to pagination
|
||||
String PAGINATION_ENABLED = "pagination-enabled";
|
||||
String START_INDEX = "start";
|
||||
String RESULT_COUNT = "length";
|
||||
|
||||
@GET
|
||||
@Path("device-count-overview")
|
||||
Response getOverviewDeviceCounts();
|
||||
|
||||
@GET
|
||||
@Path("device-counts-by-potential-vulnerabilities")
|
||||
Response getDeviceCountsByPotentialVulnerabilities();
|
||||
|
||||
@GET
|
||||
@Path("non-compliant-device-counts-by-features")
|
||||
Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex,
|
||||
@QueryParam(RESULT_COUNT) int resultCount);
|
||||
|
||||
@GET
|
||||
@Path("device-counts-by-groups")
|
||||
Response getDeviceCountsByGroups(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership);
|
||||
|
||||
@GET
|
||||
@Path("feature-non-compliant-device-counts-by-groups")
|
||||
Response getFeatureNonCompliantDeviceCountsByGroups(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership);
|
||||
@GET
|
||||
@Path("filtered-device-count-over-total")
|
||||
Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership);
|
||||
|
||||
@GET
|
||||
@Path("feature-non-compliant-device-count-over-total")
|
||||
Response getFeatureNonCompliantDeviceCountOverTotal(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership);
|
||||
|
||||
@GET
|
||||
@Path("devices-with-details")
|
||||
Response getDevicesWithDetails(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership,
|
||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
||||
@QueryParam(START_INDEX) int startIndex,
|
||||
@QueryParam(RESULT_COUNT) int resultCount);
|
||||
|
||||
@GET
|
||||
@Path("feature-non-compliant-devices-with-details")
|
||||
Response getFeatureNonCompliantDevicesWithDetails(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership,
|
||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
||||
@QueryParam(START_INDEX) int startIndex,
|
||||
@QueryParam(RESULT_COUNT) int resultCount);
|
||||
}
|
@ -0,0 +1,687 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
|
||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.BasicFilterSet;
|
||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroup;
|
||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceWithDetails;
|
||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.ExtendedFilterSet;
|
||||
import org.wso2.carbon.device.mgt.analytics.dashboard.exception.*;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardGadgetDataWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardPaginationGadgetDataWrapper;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class consists of dashboard related REST APIs
|
||||
* to be consumed by individual client gadgets such as
|
||||
* [1] Overview of Devices,
|
||||
* [2] Potential Vulnerabilities,
|
||||
* [3] Non-compliant Devices by Features,
|
||||
* [4] Device Groupings and etc.
|
||||
*/
|
||||
|
||||
@Consumes({"application/json"})
|
||||
@Produces({"application/json"})
|
||||
|
||||
@SuppressWarnings("NonJaxWsWebServices")
|
||||
public class DashboardImpl implements Dashboard{
|
||||
|
||||
private static Log log = LogFactory.getLog(DashboardImpl.class);
|
||||
|
||||
private static final String FLAG_TRUE = "true";
|
||||
private static final String FLAG_FALSE = "false";
|
||||
// Constants related to common error-response messages
|
||||
private static final String INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY = "Received an invalid value for " +
|
||||
"query parameter : " + POTENTIAL_VULNERABILITY + ", Should be either NON_COMPLIANT or UNMONITORED.";
|
||||
private static final String INVALID_QUERY_PARAM_VALUE_START_INDEX = "Received an invalid value for " +
|
||||
"query parameter : " + START_INDEX + ", Should not be lesser than 0.";
|
||||
private static final String INVALID_QUERY_PARAM_VALUE_RESULT_COUNT = "Received an invalid value for " +
|
||||
"query parameter : " + RESULT_COUNT + ", Should not be lesser than 5.";
|
||||
private static final String INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Received an invalid value for " +
|
||||
"query parameter : " + PAGINATION_ENABLED + ", Should be either true or false.";
|
||||
private static final String REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE = "Missing required query " +
|
||||
"parameter : " + NON_COMPLIANT_FEATURE_CODE;
|
||||
private static final String REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Missing required query " +
|
||||
"parameter : " + PAGINATION_ENABLED;
|
||||
private static final String ERROR_IN_RETRIEVING_REQUESTED_DATA = "Error in retrieving requested data.";
|
||||
|
||||
@GET
|
||||
@Path("device-count-overview")
|
||||
public Response getOverviewDeviceCounts() {
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
|
||||
|
||||
// getting total device count
|
||||
DeviceCountByGroup totalDeviceCount;
|
||||
try {
|
||||
totalDeviceCount = gadgetDataService.getTotalDeviceCount();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve total device count.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
List<DeviceCountByGroup> totalDeviceCountInListEntry = new ArrayList<>();
|
||||
totalDeviceCountInListEntry.add(totalDeviceCount);
|
||||
|
||||
dashboardGadgetDataWrapper1.setContext("Total-device-count");
|
||||
dashboardGadgetDataWrapper1.setGroupingAttribute(null);
|
||||
dashboardGadgetDataWrapper1.setData(totalDeviceCountInListEntry);
|
||||
|
||||
// getting device counts by connectivity statuses
|
||||
List<DeviceCountByGroup> deviceCountsByConnectivityStatuses;
|
||||
try {
|
||||
deviceCountsByConnectivityStatuses = gadgetDataService.getDeviceCountsByConnectivityStatuses();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve device counts by connectivity statuses.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();
|
||||
|
||||
dashboardGadgetDataWrapper2.setContext("Device-counts-by-connectivity-statuses");
|
||||
dashboardGadgetDataWrapper2.setGroupingAttribute(CONNECTIVITY_STATUS);
|
||||
dashboardGadgetDataWrapper2.setData(deviceCountsByConnectivityStatuses);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper1);
|
||||
responsePayload.add(dashboardGadgetDataWrapper2);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("device-counts-by-potential-vulnerabilities")
|
||||
public Response getDeviceCountsByPotentialVulnerabilities() {
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
List<DeviceCountByGroup> deviceCountsByPotentialVulnerabilities;
|
||||
try {
|
||||
deviceCountsByPotentialVulnerabilities = gadgetDataService.getDeviceCountsByPotentialVulnerabilities();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve device counts by potential vulnerabilities.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper.setContext("Device-counts-by-potential-vulnerabilities");
|
||||
dashboardGadgetDataWrapper.setGroupingAttribute(POTENTIAL_VULNERABILITY);
|
||||
dashboardGadgetDataWrapper.setData(deviceCountsByPotentialVulnerabilities);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("non-compliant-device-counts-by-features")
|
||||
public Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex,
|
||||
@QueryParam(RESULT_COUNT) int resultCount) {
|
||||
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
DashboardPaginationGadgetDataWrapper
|
||||
dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
|
||||
|
||||
PaginationResult paginationResult;
|
||||
try {
|
||||
paginationResult = gadgetDataService.
|
||||
getNonCompliantDeviceCountsByFeatures(startIndex, resultCount);
|
||||
} catch (InvalidStartIndexValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a non-compliant set " +
|
||||
"of device counts by features.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_START_INDEX).build();
|
||||
} catch (InvalidResultCountValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a non-compliant set " +
|
||||
"of device counts by features.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a non-compliant set of device counts by features.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
dashboardPaginationGadgetDataWrapper.setContext("Non-compliant-device-counts-by-features");
|
||||
dashboardPaginationGadgetDataWrapper.setGroupingAttribute(NON_COMPLIANT_FEATURE_CODE);
|
||||
dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
|
||||
dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());
|
||||
|
||||
List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardPaginationGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("device-counts-by-groups")
|
||||
public Response getDeviceCountsByGroups(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership) {
|
||||
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
||||
filterSet.setConnectivityStatus(connectivityStatus);
|
||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
// creating device-Counts-by-platforms Data Wrapper
|
||||
List<DeviceCountByGroup> deviceCountsByPlatforms;
|
||||
try {
|
||||
deviceCountsByPlatforms = gadgetDataService.getDeviceCountsByPlatforms(filterSet);
|
||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of device counts by platforms.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of device counts by platforms.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper1.setContext("Device-counts-by-platforms");
|
||||
dashboardGadgetDataWrapper1.setGroupingAttribute(PLATFORM);
|
||||
dashboardGadgetDataWrapper1.setData(deviceCountsByPlatforms);
|
||||
|
||||
// creating device-Counts-by-ownership-types Data Wrapper
|
||||
List<DeviceCountByGroup> deviceCountsByOwnerships;
|
||||
try {
|
||||
deviceCountsByOwnerships = gadgetDataService.getDeviceCountsByOwnershipTypes(filterSet);
|
||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of device counts by ownerships.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of device counts by ownerships.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper2.setContext("Device-counts-by-ownerships");
|
||||
dashboardGadgetDataWrapper2.setGroupingAttribute(OWNERSHIP);
|
||||
dashboardGadgetDataWrapper2.setData(deviceCountsByOwnerships);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper1);
|
||||
responsePayload.add(dashboardGadgetDataWrapper2);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("feature-non-compliant-device-counts-by-groups")
|
||||
public Response getFeatureNonCompliantDeviceCountsByGroups(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership) {
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
BasicFilterSet filterSet = new BasicFilterSet();
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
// creating feature-non-compliant-device-Counts-by-platforms Data Wrapper
|
||||
List<DeviceCountByGroup> featureNonCompliantDeviceCountsByPlatforms;
|
||||
try {
|
||||
featureNonCompliantDeviceCountsByPlatforms = gadgetDataService.
|
||||
getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet);
|
||||
} catch (InvalidFeatureCodeValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of feature " +
|
||||
"non-compliant device counts by platforms.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of feature non-compliant " +
|
||||
"device counts by platforms.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper1.setContext("Feature-non-compliant-device-counts-by-platforms");
|
||||
dashboardGadgetDataWrapper1.setGroupingAttribute(PLATFORM);
|
||||
dashboardGadgetDataWrapper1.setData(featureNonCompliantDeviceCountsByPlatforms);
|
||||
|
||||
// creating feature-non-compliant-device-Counts-by-ownership-types Data Wrapper
|
||||
List<DeviceCountByGroup> featureNonCompliantDeviceCountsByOwnerships;
|
||||
try {
|
||||
featureNonCompliantDeviceCountsByOwnerships = gadgetDataService.
|
||||
getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet);
|
||||
} catch (InvalidFeatureCodeValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of feature " +
|
||||
"non-compliant device counts by ownerships.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of feature non-compliant " +
|
||||
"device counts by ownerships.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper2.setContext("Feature-non-compliant-device-counts-by-ownerships");
|
||||
dashboardGadgetDataWrapper2.setGroupingAttribute(OWNERSHIP);
|
||||
dashboardGadgetDataWrapper2.setData(featureNonCompliantDeviceCountsByOwnerships);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper1);
|
||||
responsePayload.add(dashboardGadgetDataWrapper2);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("filtered-device-count-over-total")
|
||||
public Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership) {
|
||||
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
||||
filterSet.setConnectivityStatus(connectivityStatus);
|
||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
// creating filteredDeviceCount Data Wrapper
|
||||
DeviceCountByGroup filteredDeviceCount;
|
||||
try {
|
||||
filteredDeviceCount = gadgetDataService.getDeviceCount(filterSet);
|
||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered device count over the total.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered device count over the total.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
// creating TotalDeviceCount Data Wrapper
|
||||
DeviceCountByGroup totalDeviceCount;
|
||||
try {
|
||||
totalDeviceCount = gadgetDataService.getTotalDeviceCount();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve the total device count over filtered.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
List<Object> filteredDeviceCountOverTotalDataWrapper = new ArrayList<>();
|
||||
filteredDeviceCountOverTotalDataWrapper.add(filteredDeviceCount);
|
||||
filteredDeviceCountOverTotalDataWrapper.add(totalDeviceCount);
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper.setContext("Filtered-device-count-over-total");
|
||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
||||
dashboardGadgetDataWrapper.setData(filteredDeviceCountOverTotalDataWrapper);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("feature-non-compliant-device-count-over-total")
|
||||
public Response getFeatureNonCompliantDeviceCountOverTotal(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership) {
|
||||
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
BasicFilterSet filterSet = new BasicFilterSet();
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
// creating featureNonCompliantDeviceCount Data Wrapper
|
||||
DeviceCountByGroup featureNonCompliantDeviceCount;
|
||||
try {
|
||||
featureNonCompliantDeviceCount = gadgetDataService.
|
||||
getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet);
|
||||
} catch (InvalidFeatureCodeValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a feature non-compliant device count over the total.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a feature non-compliant device count over the total.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
// creating TotalDeviceCount Data Wrapper
|
||||
DeviceCountByGroup totalDeviceCount;
|
||||
try {
|
||||
totalDeviceCount = gadgetDataService.getTotalDeviceCount();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve the total device count over filtered feature non-compliant.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
List<Object> featureNonCompliantDeviceCountOverTotalDataWrapper = new ArrayList<>();
|
||||
featureNonCompliantDeviceCountOverTotalDataWrapper.add(featureNonCompliantDeviceCount);
|
||||
featureNonCompliantDeviceCountOverTotalDataWrapper.add(totalDeviceCount);
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper.setContext("Feature-non-compliant-device-count-over-total");
|
||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
||||
dashboardGadgetDataWrapper.setData(featureNonCompliantDeviceCountOverTotalDataWrapper);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("devices-with-details")
|
||||
public Response getDevicesWithDetails(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership,
|
||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
||||
@QueryParam(START_INDEX) int startIndex,
|
||||
@QueryParam(RESULT_COUNT) int resultCount) {
|
||||
|
||||
if (paginationEnabled == null) {
|
||||
|
||||
log.error("Bad request on retrieving a filtered set of devices with details @ " +
|
||||
"Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
||||
|
||||
} else if (FLAG_TRUE.equals(paginationEnabled)) {
|
||||
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
||||
filterSet.setConnectivityStatus(connectivityStatus);
|
||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
PaginationResult paginationResult;
|
||||
try {
|
||||
paginationResult = gadgetDataService.
|
||||
getDevicesWithDetails(filterSet, startIndex, resultCount);
|
||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
||||
} catch (InvalidStartIndexValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_START_INDEX).build();
|
||||
} catch (InvalidResultCountValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardPaginationGadgetDataWrapper
|
||||
dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
|
||||
dashboardPaginationGadgetDataWrapper.setContext("Filtered-and-paginated-devices-with-details");
|
||||
dashboardPaginationGadgetDataWrapper.setGroupingAttribute(null);
|
||||
dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
|
||||
dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());
|
||||
|
||||
List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardPaginationGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
|
||||
} else if (FLAG_FALSE.equals(paginationEnabled)) {
|
||||
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
||||
filterSet.setConnectivityStatus(connectivityStatus);
|
||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
List<DeviceWithDetails> devicesWithDetails;
|
||||
try {
|
||||
devicesWithDetails = gadgetDataService.getDevicesWithDetails(filterSet);
|
||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper.setContext("Filtered-devices-with-details");
|
||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
||||
dashboardGadgetDataWrapper.setData(devicesWithDetails);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
|
||||
} else {
|
||||
|
||||
log.error("Bad request on retrieving a filtered set of devices with details @ " +
|
||||
"Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("feature-non-compliant-devices-with-details")
|
||||
public Response getFeatureNonCompliantDevicesWithDetails(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
||||
@QueryParam(PLATFORM) String platform,
|
||||
@QueryParam(OWNERSHIP) String ownership,
|
||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
||||
@QueryParam(START_INDEX) int startIndex,
|
||||
@QueryParam(RESULT_COUNT) int resultCount) {
|
||||
if (paginationEnabled == null) {
|
||||
|
||||
log.error("Bad request on retrieving a filtered set of feature non-compliant devices with " +
|
||||
"details @ Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
||||
|
||||
} else if (FLAG_TRUE.equals(paginationEnabled)) {
|
||||
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
BasicFilterSet filterSet = new BasicFilterSet();
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
PaginationResult paginationResult;
|
||||
try {
|
||||
paginationResult = gadgetDataService.
|
||||
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode,
|
||||
filterSet, startIndex, resultCount);
|
||||
} catch (InvalidFeatureCodeValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
||||
"feature non-compliant devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
||||
} catch (InvalidStartIndexValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
||||
"feature non-compliant devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_START_INDEX).build();
|
||||
} catch (InvalidResultCountValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
||||
"feature non-compliant devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of feature " +
|
||||
"non-compliant devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardPaginationGadgetDataWrapper
|
||||
dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
|
||||
dashboardPaginationGadgetDataWrapper.
|
||||
setContext("Filtered-and-paginated-feature-non-compliant-devices-with-details");
|
||||
dashboardPaginationGadgetDataWrapper.setGroupingAttribute(null);
|
||||
dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
|
||||
dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());
|
||||
|
||||
List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardPaginationGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
|
||||
} else if (FLAG_FALSE.equals(paginationEnabled)) {
|
||||
|
||||
// getting gadget data service
|
||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
||||
|
||||
// constructing filter set
|
||||
BasicFilterSet filterSet = new BasicFilterSet();
|
||||
filterSet.setPlatform(platform);
|
||||
filterSet.setOwnership(ownership);
|
||||
|
||||
List<DeviceWithDetails> featureNonCompliantDevicesWithDetails;
|
||||
try {
|
||||
featureNonCompliantDevicesWithDetails = gadgetDataService.
|
||||
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet);
|
||||
} catch (InvalidFeatureCodeValueException e) {
|
||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
||||
"feature non-compliant devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
||||
} catch (DataAccessLayerException e) {
|
||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
||||
"@ Dashboard API layer to retrieve a filtered set of feature " +
|
||||
"non-compliant devices with details.", e);
|
||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
||||
}
|
||||
|
||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
||||
dashboardGadgetDataWrapper.setContext("Filtered-feature-non-compliant-devices-with-details");
|
||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
||||
dashboardGadgetDataWrapper.setData(featureNonCompliantDevicesWithDetails);
|
||||
|
||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
||||
responsePayload.add(dashboardGadgetDataWrapper);
|
||||
|
||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||
|
||||
} else {
|
||||
|
||||
log.error("Bad request on retrieving a filtered set of feature non-compliant devices with " +
|
||||
"details @ Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
||||
entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
public class DashboardGadgetDataWrapper {
|
||||
|
||||
private String context;
|
||||
private String groupingAttribute;
|
||||
private List<?> data;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getGroupingAttribute() {
|
||||
return groupingAttribute;
|
||||
}
|
||||
|
||||
public void setGroupingAttribute(String groupingAttribute) {
|
||||
this.groupingAttribute = groupingAttribute;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public List<?> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<?> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class DashboardPaginationGadgetDataWrapper extends DashboardGadgetDataWrapper {
|
||||
|
||||
private int totalRecordCount;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public int getTotalRecordCount() {
|
||||
return totalRecordCount;
|
||||
}
|
||||
|
||||
public void setTotalRecordCount(int totalRecordCount) {
|
||||
this.totalRecordCount = totalRecordCount;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.operation.mgt;
|
||||
|
||||
public class Activity {
|
||||
|
||||
public enum Type {
|
||||
CONFIG, MESSAGE, INFO, COMMAND, PROFILE, POLICY
|
||||
}
|
||||
|
||||
private String activityId;
|
||||
private String code;
|
||||
private Type type;
|
||||
private String createdTimeStamp;
|
||||
|
||||
public String getActivityId() {
|
||||
return activityId;
|
||||
}
|
||||
|
||||
public void setActivityId(String activityId) {
|
||||
this.activityId = activityId;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getCreatedTimeStamp() {
|
||||
return createdTimeStamp;
|
||||
}
|
||||
|
||||
public void setCreatedTimeStamp(String createdTimeStamp) {
|
||||
this.createdTimeStamp = createdTimeStamp;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.operation.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ActivityStatus {
|
||||
|
||||
public enum Status {
|
||||
IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED
|
||||
}
|
||||
private DeviceIdentifier deviceIdentifier;
|
||||
private Status status;
|
||||
private List<OperationResponse> responses;
|
||||
private String updatedTimestamp;
|
||||
|
||||
public DeviceIdentifier getDeviceIdentifier() {
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
|
||||
this.deviceIdentifier = deviceIdentifier;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<OperationResponse> getResponses() {
|
||||
return responses;
|
||||
}
|
||||
|
||||
public void setResponses(List<OperationResponse> responses) {
|
||||
this.responses = responses;
|
||||
}
|
||||
|
||||
public String getUpdatedTimestamp() {
|
||||
return updatedTimestamp;
|
||||
}
|
||||
|
||||
public void setUpdatedTimestamp(String updatedTimestamp) {
|
||||
this.updatedTimestamp = updatedTimestamp;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
}}
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/operation-mod.js"}}
|
||||
{{/zone}}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue