updated from master

apim420
Amalka Subasinghe 1 year ago
commit 46ee81e78d

@ -1,141 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>application-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.application.mgt.addons</artifactId>
<name>Entgra - Application Management Add-Ons</name>
<description>Entgra - Application Management Add-Ons</description>
<url>https://entgra.io</url>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${io.entgra.device.mgt.core.version}</Bundle-Version>
<Bundle-Description>Application Management Add-Ons Bundle</Bundle-Description>
<Import-Package>
com.google.gson;version="[2.9,3)",
io.entgra.device.mgt.core.application.mgt.addons.jaxrs,
javax.servlet;version="[4.0,5)",
javax.servlet.http;version="[4.0,5)",
javax.validation;version="[1.1,2)",
javax.validation.executable;version="[1.1,2)",
javax.ws.rs;version="[2.1,3)",
javax.ws.rs.core;version="[2.1,3)",
javax.ws.rs.ext;version="[2.1,3)",
org.apache.commons.logging;version="[1.2,2)",
org.apache.cxf.interceptor;version="[3.5,4)",
org.apache.cxf.jaxrs.lifecycle;version="[3.5,4)",
org.apache.cxf.jaxrs.model;version="[3.5,4)",
org.apache.cxf.message;version="[3.5,4)",
org.apache.cxf.phase;version="[3.5,4)"
</Import-Package>
<Export-Package>
io.entgra.device.mgt.core.application.mgt.addons.*
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
</project>

@ -1,47 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.addons;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class ApiOriginFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
chain.doFilter(request, response);
}
public void destroy() {
//do nothing
}
public void init(FilterConfig filterConfig) throws ServletException {
//do nothing
}
}

@ -1,54 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.addons;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* io.entgra.device.mgt.core.application.mgt.addons.FileStreamingOutput to allow the user to send the files as Stream.
*/
public class FileStreamingOutput implements StreamingOutput {
private InputStream inputStream;
public FileStreamingOutput(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
try {
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
outputStream.write(buffer);
outputStream.flush();
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
}

@ -1,86 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.addons;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.entgra.device.mgt.core.application.mgt.addons.jaxrs.AnnotationExclusionStrategy;
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;
/**
* This provider is used to change a JSON object to complex object and inversely in request and response.
*/
@Provider
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public class JSONMessageHandler 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()
.setDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
.setExclusionStrategies(new AnnotationExclusionStrategy());
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 {
try (InputStreamReader reader = new InputStreamReader(entityStream, UTF_8)) {
return getGson().fromJson(reader, type);
}
}
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 {
try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8)) {
getGson().toJson(object, type, writer);
}
}
}

@ -1,72 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.addons;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.entgra.device.mgt.core.application.mgt.addons.jaxrs.AnnotationExclusionStrategy;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import javax.ws.rs.Consumes;
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.Provider;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* Provider for the text/plain type of input. Particularly use-ful for the complex objects sent along with Multipart
* request.
*/
@Provider
@Consumes(MediaType.TEXT_PLAIN)
public class MultipartCustomProvider implements MessageBodyReader<Object> {
private Gson gson;
public MultipartCustomProvider() {
final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
.setExclusionStrategies(new AnnotationExclusionStrategy());
gson = gsonBuilder.create();
}
@Override
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
return !aClass.equals(Attachment.class);
}
@Override
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> headers, InputStream inputStream) throws IOException,
WebApplicationException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String jsonString = result.toString();
JsonObject obj = new JsonParser().parse(jsonString).getAsJsonObject();
return gson.fromJson(obj, type);
}
}

@ -1,122 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.addons;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.executable.ExecutableValidator;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;
public class ValidationInterceptor extends AbstractPhaseInterceptor<Message> {
private Log log = LogFactory.getLog(getClass());
private Validator validator = null; //validator interface is thread-safe
public ValidationInterceptor() {
super(Phase.PRE_INVOKE);
ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory();
validator = defaultFactory.getValidator();
if (validator == null) {
log.warn("Bean Validation provider could not be found, no validation will be performed");
} else {
log.debug("Validation In-Interceptor initialized successfully");
}
}
@Override
public void handleMessage(Message message) throws Fault {
final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
if (operationResource == null) {
log.info("OperationResourceInfo is not available, skipping validation");
return;
}
final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
if (classResource == null) {
log.info("ClassResourceInfo is not available, skipping validation");
return;
}
final ResourceProvider resourceProvider = classResource.getResourceProvider();
if (resourceProvider == null) {
log.info("ResourceProvider is not available, skipping validation");
return;
}
final List<Object> arguments = MessageContentsList.getContentsList(message);
final Method method = operationResource.getAnnotatedMethod();
final Object instance = resourceProvider.getInstance(message);
if (method != null && arguments != null) {
//validate the parameters(arguments) over the invoked method
validate(method, arguments.toArray(), instance);
//validate the fields of each argument
for (Object arg : arguments) {
if (arg != null)
validate(arg);
}
}
}
public <T> void validate(final Method method, final Object[] arguments, final T instance) {
if (validator == null) {
log.warn("Bean Validation provider could not be found, no validation will be performed");
return;
}
ExecutableValidator methodValidator = validator.forExecutables();
Set<ConstraintViolation<T>> violations = methodValidator.validateParameters(instance,
method, arguments);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
public <T> void validate(final T object) {
if (validator == null) {
log.warn("Bean Validation provider could be found, no validation will be performed");
return;
}
Set<ConstraintViolation<T>> violations = validator.validate(object);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
public void handleFault(org.apache.cxf.message.Message messageParam) {
}
}

@ -1,37 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.addons.jaxrs;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
/**
* This class is used to exclude certain fields when serializing and de-serializing based on the annotation.
*/
public class AnnotationExclusionStrategy implements ExclusionStrategy {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getAnnotation(Exclude.class) != null;
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
}

@ -1,31 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.addons.jaxrs;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This class is the representation of custom developed Exclude annotation.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Exclude {
}

@ -1,226 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>application-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.application.mgt.api</artifactId>
<packaging>war</packaging>
<name>Entgra - Application Management API</name>
<description>Entgra - Application Management API</description>
<url>https://entgra.io</url>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#application-mgt#v1.0</warName>
</configuration>
</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>
<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="api#application-mgt#v1.0.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>
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</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.utils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.common</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>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.addons</artifactId>
</dependency>
<dependency>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
</project>

@ -1,161 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.api;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.swagger.annotations.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* APIs to handle application management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Application Management Artifact Download Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ApplicationManagementArtifactDownloadService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/artifact"),
})
}
)
)
@Path("/artifact")
@Api(value = "ApplicationDTO Management Artifact Downloading Service")
@Produces(MediaType.APPLICATION_JSON)
public interface ArtifactDownloadAPI {
@GET
@Path("/{tenantId}/{appHashValue}/{folderName}/{fileName}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@ApiOperation(
produces = MediaType.APPLICATION_OCTET_STREAM,
httpMethod = "GET",
value = "get application management UI configuration",
notes = "This will get all UI configuration of application management"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully got UI config.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. There doesn't have an defined UI config." +
"query."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the UI config.",
response = ErrorResponse.class)
})
Response getArtifact(
@ApiParam(
name = "tenantId",
value = "Tenant Id of the application artifact belongs.",
required = true)
@PathParam("tenantId") int tenantId,
@ApiParam(
name = "appHashValue",
value = "Hash value of the application release.",
required = true)
@PathParam("appHashValue") String uuid,
@ApiParam(
name = "folderName",
value = "Name of the folder where the artifact store.",
required = true)
@PathParam("folderName") String folderName,
@ApiParam(
name = "fileName",
value = "Name of the artifact",
required = true)
@PathParam("fileName") String fileName);
@GET
@Path("/plist/{uuid}")
@Produces(MediaType.TEXT_XML)
@ApiOperation(
produces = MediaType.TEXT_XML,
httpMethod = "GET",
value = "Get plist artifact content of an application",
notes = "Get plist artifact content of an application"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved plist artifact content.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. Plist artifact content not found for the application."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while retrieving plist artifact content.",
response = ErrorResponse.class)
})
Response getPlistArtifact(
@ApiParam(
name = "uuid",
value = "UUID of the application release.",
required = true)
@PathParam("uuid") String uuid);
@GET
@Path("/{deviceType}/agent")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@ApiOperation(
produces = MediaType.APPLICATION_OCTET_STREAM,
httpMethod = "GET",
value = "get the agent of a device type",
notes = "This will download an agent depending on the device type"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully got the agent.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. There doesn't have an defined agent for the resource." +
"query."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the agent.",
response = ErrorResponse.class)
})
Response getDeviceTypeAgent(
@ApiParam(
name = "deviceType",
value = "Device type of the agent.",
example = "android",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "tenantDomain",
value = "Tenant Domain of the application artifact belongs.",
defaultValue = "carbon.super")
@QueryParam("tenantDomain") String tenantDomain);
}

@ -1,156 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.api.impl;
import io.entgra.device.mgt.core.application.mgt.api.ArtifactDownloadAPI;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.AppmDataHandler;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Implementation of ApplicationDTO Management related APIs.
*/
@Produces({"application/json"})
@Path("/artifact")
public class ArtifactDownloadAPIImpl implements ArtifactDownloadAPI {
private static final Log log = LogFactory.getLog(ArtifactDownloadAPIImpl.class);
@GET
@Override
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/{tenantId}/{appHashValue}/{folderName}/{fileName}")
public Response getArtifact(
@PathParam("tenantId") int tenantId,
@PathParam("appHashValue") String appHashValue,
@PathParam("folderName") String folderName,
@PathParam("fileName") String fileName) {
AppmDataHandler dataHandler = APIUtil.getDataHandler();
try (InputStream fileInputStream = dataHandler
.getArtifactStream(tenantId, appHashValue, folderName, fileName)) {
byte[] content = IOUtils.toByteArray(fileInputStream);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
Response.ResponseBuilder response = Response
.ok(binaryDuplicate, MediaType.APPLICATION_OCTET_STREAM);
response.status(Response.Status.OK);
response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.header("Content-Length", content.length);
return response.build();
} catch (IOException e) {
String msg = "Error occurred while creating input stream from buffer array. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for app hash value: " + appHashValue
+ " and file name: " + fileName;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid data is used with the request to get input stream of the application release. UUID: "
+ appHashValue + " and file name: " + fileName;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application release artifact file. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (IOException e) {
String msg = "Error occurred while getting the byte array of application release artifact file. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
@Produces(MediaType.TEXT_XML)
@Path("/plist/{uuid}")
public Response getPlistArtifact(@PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
String plistContent = applicationManager.getPlistArtifact(uuid);
return Response.status(Response.Status.OK).entity(plistContent).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application plist artifact file.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/{deviceType}/agent")
public Response getDeviceTypeAgent(@PathParam("deviceType") String deviceType,
@DefaultValue("carbon.super")
@QueryParam("tenantDomain") String tenantDomain) {
AppmDataHandler dataHandler = APIUtil.getDataHandler();
try (InputStream fileInputStream = dataHandler.getAgentStream(tenantDomain, deviceType)) {
byte[] content = IOUtils.toByteArray(fileInputStream);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
Response.ResponseBuilder response = Response
.ok(binaryDuplicate, MediaType.APPLICATION_OCTET_STREAM);
response.status(Response.Status.OK);
String fileName = Constants.AGENT_FILE_NAMES.get(deviceType);
response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.header("Content-Length", content.length);
return response.build();
} catch (IOException e) {
String msg = "Error occurred while creating input stream from buffer array. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (NotFoundException e) {
String msg = "Requesting device type agent for unsupported device type " + deviceType;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e){
String msg = "Couldn't find the device type agent in the system.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the device type agent. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (IOException e) {
String msg = "Error occurred while getting the byte array of application release artifact file. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<!-- 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>
</PermissionConfiguration>

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<!--
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>CXF3,Carbon</Environments>
</Classloading>

@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
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 http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<jaxrs:server id="applicationMgtCommonService" address="/">
<jaxrs:serviceBeans>
<ref bean="applicationMgtArtifactService"/>
<ref bean="swaggerResource"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="multipartProvider"/>
<ref bean="swaggerWriter"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="io.entgra.device.mgt.core.application.mgt.api"/>
<property name="version" value="1.0"/>
<property name="host" value="localhost:9443"/>
<property name="schemes" value="https" />
<property name="basePath" value="/api/application-mgt-publisher/v1.0"/>
<property name="title" value="Application Artifact Management APIs"/>
<property name="contact" value="bizdev-group@entgra.io"/>
<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="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor" class="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor"/>
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="applicationMgtArtifactService" class="io.entgra.device.mgt.core.application.mgt.api.impl.ArtifactDownloadAPIImpl"/>
<bean id="jsonProvider" class="io.entgra.device.mgt.core.application.mgt.addons.JSONMessageHandler"/>
<bean id="multipartProvider" class="io.entgra.device.mgt.core.application.mgt.addons.MultipartCustomProvider"/>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor"/>
</cxf:inInterceptors>
</cxf:bus>
</beans>

@ -1,129 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>Application Management Webapp</display-name>
<servlet>
<description>JAX-WS/JAX-RS Application 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>
<!-- configure a security filter -->
<init-param>
<param-name>swagger.security.filter</param-name>
<param-value>ApiAuthorizationFilterImpl</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</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>doAuthentication</param-name>
<param-value>true</param-value>
</context-param>
<!-- Below configuration is used to redirect http requests to https -->
<!-- Below configuration is commented because artifact download API is accessed from the device -->
<!-- <security-constraint>-->
<!-- <web-resource-collection>-->
<!-- <web-resource-name>ApplicationMgt-Admin</web-resource-name>-->
<!-- <url-pattern>/*</url-pattern>-->
<!-- </web-resource-collection>-->
<!-- <user-data-constraint>-->
<!-- <transport-guarantee>CONFIDENTIAL</transport-guarantee>-->
<!-- </user-data-constraint>-->
<!-- </security-constraint>-->
<!--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>
<context-param>
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>io.entgra.device.mgt.core.application.mgt.addons.ApiOriginFilter</filter-class>
</filter>
<filter>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class>
<init-param>
<param-name>patterns</param-name>
<param-value>text/html" ,application/json" ,text/plain</param-value>
</init-param>
<init-param>
<param-name>filterAction</param-name>
<param-value>enforce</param-value>
</init-param>
<init-param>
<param-name>httpHeaders</param-name>
<param-value>Cache-Control: no-store, no-cache, must-revalidate, private</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>nonSecuredEndPoints</param-name>
<param-value>
/api/application-mgt/v1.0/artifact/.*,
/api/application-mgt/v1.0/config/.*
</param-value>
</context-param>
</web-app>

@ -1,226 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>application-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.application.mgt.publisher.api</artifactId>
<packaging>war</packaging>
<name>Entgra - Application Management Publisher API</name>
<description>Entgra - Application Management Publisher API</description>
<url>https://entgra.io</url>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#application-mgt-publisher#v1.0</warName>
</configuration>
</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>
<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="api#application-mgt-publisher#v1.0.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>
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</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.utils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.common</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>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.addons</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.device.mgt.common</artifactId>
</dependency>
</dependencies>
</project>

@ -1,383 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.publisher.api;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.dto.IdentityServerDTO;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.ApplicationWrapper;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.CustomAppWrapper;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.PublicAppWrapper;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppWrapper;
import io.swagger.annotations.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Service Provider Application Management Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "SPApplicationService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-publisher/v1.0/identity-server-applications"),
})
}
),
tags = {
@Tag(name = "application_management, device_management", description = "App publisher related APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "view a service provider applications",
description = "Get service provider application details",
key = "perm:app:publisher:service-provider:view",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/view"}
),
@Scope(
name = "Create new identity server",
description = "Connect to new identity server",
key = "perm:app:publisher:service-provider:connect",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/connect"}
),
@Scope(
name = "Create a service provider application",
description = "Create an application and attach (map) to service provider",
key = "perm:app:publisher:service-provider:create",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/create"}
),
@Scope(
name = "Attach a service provider application",
description = "Map an application to service provider",
key = "perm:app:publisher:service-provider:attach",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/attach"}
),
@Scope(
name = "Detach a service provider application",
description = "Remove an application from service provider",
key = "perm:app:publisher:service-provider:detach",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/detach"}
)
}
)
@Path("/identity-server-applications")
@Api(value = "SPApplication Management")
@Produces(MediaType.APPLICATION_JSON)
public interface SPApplicationService {
String SCOPE = "scope";
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/identity-servers/identity-service-providers")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get available identity service providers",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
})
}
)
Response getIdentityServiceProviders();
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/identity-servers")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get all identity servers",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
})
}
)
Response getIdentityServers();
@Path("/identity-servers/{id}")
@DELETE
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "get identity server by id",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:connect")
})
}
)
Response deleteIdentityServer(@PathParam("id") int id);
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/identity-servers/{id}")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get identity server by id",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
})
}
)
Response getIdentityServer(@PathParam("id") int id);
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/identity-servers")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "create new identity server",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:connect")
})
}
)
Response createIdentityServer(IdentityServerDTO identityServerDTO);
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/identity-servers/{id}")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "edit existing identity server",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:connect")
})
}
)
Response updateIdentityServer(IdentityServerDTO identityServerDTO, @PathParam("id") int id);
@GET
@Path("/identity-servers/identity-server-name")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Check if identity server name is already exists",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
})
}
)
Response isIdentityServerNameExists(
@QueryParam("identityServerName") String identityServerName);
@GET
@Path("/identity-servers/identity-server-url")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Check if identity server url is already exists",
tags = "Identity Server Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
})
}
)
Response isIdentityServerUrlExists(
@QueryParam("identityServerUrl") String identityServerUrl);
/**
* This method is used to register an APIM application for tenant domain.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{identity-server-id}/service-providers")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get service providers by identity server id",
notes = "This will get service providers with the existing applications",
tags = "Service Provider Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
})
}
)
Response getServiceProviders(@QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset,
@PathParam("identity-server-id") int identityServerId);
@Path("/{identity-server-id}/service-provider/{service-provider-id}/attach")
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "map application to service provider",
notes = "This will map a given list application ids with the given service provider id",
tags = "Service Provider Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:attach")
})
}
)
Response attachApps(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds);
/**
* This method is used to register an APIM application for tenant domain.
*/
@Path("/{identity-server-id}/service-provider/{service-provider-id}/detach")
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Remove mapping with service provider of the given application ids",
notes = "This will remove applications from service provider",
tags = "Service Provider Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:detach")
})
}
)
Response detachApps(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds);
/**
* This method is used to register an APIM application for tenant domain.
*/
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/ent-app")
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create enterprise application and attach to service provider",
notes = "This will get create an enterprise application and map with service provider",
tags = "Service Provider Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
})
},
nickname = "createEntAppForSP"
)
Response createEntApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-published") boolean isPublished);
/**
* This method is used to register an APIM application for tenant domain.
*/
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/public-app")
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create public application and attach to service provider",
notes = "This will get create a public application and map with service provider",
tags = "Service Provider Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
})
},
nickname = "createPubAppForSP"
)
Response createPubApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-published") boolean isPublished);
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create web application and attach to service provider",
notes = "This will get create a web application and map with service provider",
tags = "Service Provider Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
})
},
nickname = "createWebAppForSP"
)
Response createWebApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-published") boolean isPublished);
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create custom application and attach to service provider",
notes = "This will get create an custom application and map with service provider",
tags = "Service Provider Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
})
}
)
Response createCustomApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-published") boolean isPublished);
}

@ -1,334 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.publisher.api.admin;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.swagger.annotations.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* APIs to handle application management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "ApplicationDTO Management Publisher Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ApplicationManagementPublisherAdminService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-publisher/v1.0/admin/applications"),
})
}
),
tags = {
@Tag(name = "application_management, device_management", description = "App publisher related Admin APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Delete Application Release",
description = "Delete Application Release",
key = "perm:admin:app:publisher:update",
roles = {"Internal/devicemgt-admin"},
permissions = {"/app-mgt/publisher/admin/application/update"}
)
}
)
@Path("/admin/applications")
@Api(value = "ApplicationDTO Management")
@Produces(MediaType.APPLICATION_JSON)
public interface ApplicationManagementPublisherAdminAPI {
String SCOPE = "scope";
@DELETE
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete application release.",
notes = "This will delete application release for given UUID",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete application release.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. There doesn't have an application release for UUID" +
"query."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting application release.",
response = ErrorResponse.class)
}) Response deleteApplicationRelease(
@ApiParam(
name = "uuid",
value = "application release UUID",
required = true)
@PathParam("uuid") String releaseUuid);
@DELETE
@Path("/{appId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete application release.",
notes = "This will delete application release for given UUID",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete application release.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. There doesn't have an application release for UUID" +
"query."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting application release.",
response = ErrorResponse.class)
}) Response deleteApplication(
@ApiParam(
name = "appId",
value = "application ID",
required = true)
@PathParam("appId") int applicatioId);
@DELETE
@Path("/tags")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete application tag",
notes = "This will delete application tag",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete registered tag.",
response = ApplicationList.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting registered tag.",
response = ErrorResponse.class)
})
Response deleteTag(
@ApiParam(
name = "tag-name",
value = "Tag Name",
required = true)
@QueryParam("tag-name") String tagName
);
@POST
@Path("/categories")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add new application categories.",
notes = "This will add new application categories",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete registered tag.",
response = ApplicationList.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Category list is either empty or null"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting registered tag.",
response = ErrorResponse.class)
})
Response addCategories(
@ApiParam(
name = "tagName",
value = "Tag Name",
required = true) List<String> categorynames
);
@PUT
@Path("/categories/rename")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Update application category",
notes = "This will update application category.",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete registered category.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. There doesn't have an category for given category name.."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting registered category.",
response = ErrorResponse.class)
})
Response renameCategory(
@ApiParam(
name = "oldCategoryName",
value = "Existing Category Name",
required = true)
@QueryParam("from") String oldCategoryName,
@ApiParam(
name = "newCategoryName",
value = "Modifying Category Name",
required = true)
@QueryParam("to") String newCategoryName
);
@DELETE
@Path("/categories")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete application category",
notes = "This will delete application category.",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted registered category.",
response = ApplicationList.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting registered category.",
response = ErrorResponse.class)
})
Response deleteCategory(
@ApiParam(
name = "category-name",
value = "Category Name",
required = true)
@QueryParam("category-name") String categoryName
);
@PUT
@Consumes("application/json")
@Path("/retire/{appId}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Retire the application with the given app Id",
notes = "This will retire the application with the given app Id",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the application identified by app Id.",
response = List.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting the application.",
response = ErrorResponse.class),
@ApiResponse(
code = 403,
message = "Don't have permission to delete the application"),
@ApiResponse(
code = 404,
message = "Application not found"),
})
Response retireApplication(
@ApiParam(
name = "appId",
value = "Application Id",
required = true)
@PathParam("appId") int applicationId
);
}

@ -1,204 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.publisher.api.admin;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.entgra.device.mgt.core.application.mgt.common.PaginationResult;
import io.swagger.annotations.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* APIs to handle admin review management related tasks in publisher.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Publisher Review Management Admin Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "PublisherReviewManagementAdminService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-publisher/v1.0/admin/reviews"),
})
}
),
tags = {
@Tag(name = "review_management", description = "Publisher Review Management related Admin APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Update a Review",
description = "Update a Review of application.",
key = "perm:admin:app:review:update",
roles = {"Internal/devicemgt-admin"},
permissions = {"/app-mgt/publisher/admin/review/update"}
),
@Scope(
name = "Get Review Details",
description = "Get review details of application.",
key = "perm:admin:app:review:view",
roles = {"Internal/devicemgt-admin"},
permissions = {"/app-mgt/publisher/admin/review/view"}
)
}
)
@Path("/admin/reviews")
@Api(value = "Publisher Review Management Admin API")
@Produces(MediaType.APPLICATION_JSON)
public interface ReviewManagementPublisherAdminAPI {
String SCOPE = "scope";
@GET
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get app release reviews",
notes = "Get all app release reviews",
tags = "Review Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved app release reviews.",
response = PaginationResult.class,
responseContainer = "PaginationResult"),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release for requested UUID."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the review list.",
response = ErrorResponse.class)
})
Response getAllReleaseReviews(
@ApiParam(
name = "uuid",
value = "uuid of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name = "offset",
value = "Starting review number.",
defaultValue = "0")
@QueryParam("offSet") int offSet,
@ApiParam(
name = "limit",
value = "Limit of paginated reviews",
defaultValue = "20")
@QueryParam("limit") int limit);
@GET
@Path("/{uuid}/release-rating")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get ratings",
notes = "Get all ratings",
tags = "Review Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved ratings.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Application release found for application release UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting ratings",
response = ErrorResponse.class)
})
Response getAppReleaseRating(
@ApiParam(
name = "uuid",
value = "uuid of the application release",
required = true)
@PathParam("uuid") String uuid);
@GET
@Path("/{uuid}/app-rating")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get app ratings",
notes = "Get all app ratings",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved ratings.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Application found which has application release of UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting ratings",
response = ErrorResponse.class)
})
Response getAppRating(
@ApiParam(
name = "uuid",
value = "uuid of the application release",
required = true)
@PathParam("uuid")
String uuid);
}

@ -1,895 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.publisher.api.impl;
import io.entgra.device.mgt.core.application.mgt.common.*;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.LifecycleManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
import io.entgra.device.mgt.core.application.mgt.common.exception.ResourceManagementException;
import io.entgra.device.mgt.core.application.mgt.common.response.Application;
import io.entgra.device.mgt.core.application.mgt.common.response.ApplicationRelease;
import io.entgra.device.mgt.core.application.mgt.common.response.Category;
import io.entgra.device.mgt.core.application.mgt.common.response.Tag;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.AppmDataHandler;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.*;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
import io.entgra.device.mgt.core.application.mgt.publisher.api.ApplicationManagementPublisherAPI;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* Implementation of Application Management related APIs.
*/
@Produces({"application/json"})
@Path("/applications")
public class ApplicationManagementPublisherAPIImpl implements ApplicationManagementPublisherAPI {
private static final Log log = LogFactory.getLog(ApplicationManagementPublisherAPIImpl.class);
@POST
@Override
@Consumes("application/json")
public Response getApplications(
@Valid Filter filter) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
if (filter == null) {
String msg = "Request Payload is null";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
ApplicationList applications = applicationManager.getApplications(filter);
return Response.status(Response.Status.OK).entity(applications).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (UnexpectedServerErrorException e) {
String msg = "Error occurred when getting supported device types by Entgra IoTS";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application list for publisher ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Consumes("application/json")
@Path("/{appId}")
public Response getApplication(
@PathParam("appId") int appId,
@QueryParam("state") String state) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
Application application = applicationManager.getApplicationById(appId, state);
if (application == null){
String msg = "Could not found an active application which has Id: " + appId;
log.error(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) {
String msg = "ApplicationDTO with application id: " + appId + " not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch(ForbiddenException e){
String msg = "You don't have permission to access the application. application id: " + appId;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}
catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application with the id " + appId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Consumes("application/json")
@Path("/release/{uuid}")
public Response getApplicationByUUID(
@PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
Application application = applicationManager.getApplicationByUuid(uuid);
if (application == null){
String msg = "Application release is in the end state of the application lifecycle flow.";
log.error(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) {
String msg = "Application Release with UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch(ForbiddenException e){
String msg = "You don't have permission to access the application release. application release UUID: : "
+ uuid;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}
catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/ent-app")
public Response createEntApp(
ApplicationWrapper applicationWrapper, @QueryParam("is-published") boolean isPublished) {
try {
return createApplication(applicationWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with ent. app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the ent. application";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Couldn't find the required artifacts to create new ent. application with the request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/web-app")
public Response createWebApp(
WebAppWrapper webAppWrapper, @QueryParam("is-published") boolean isPublished) {
try {
return createApplication(webAppWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with web app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the web application";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Couldn't find the required artifacts to create new web application with the request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/public-app")
public Response createPubApp(
PublicAppWrapper publicAppWrapper, @QueryParam("is-published") boolean isPublished) {
try {
return createApplication(publicAppWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with pub app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the public app.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Couldn't find the required artifacts to create new public application with the request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/custom-app")
public Response createCustomApp(
CustomAppWrapper customAppWrapper, @QueryParam("is-published") boolean isPublished) {
try {
return createApplication(customAppWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with custom app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating a custom application";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Couldn't find the required artifacts to create new custom application with the request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/ent-app/{appId}")
public Response createEntAppRelease(
@PathParam("deviceType") String deviceTypeName,
@PathParam("appId") int appId,
EntAppReleaseWrapper entAppReleaseWrapper,
@QueryParam("is-published") boolean isPublished) {
try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateEntAppReleaseCreatingRequest(entAppReleaseWrapper, deviceTypeName);
ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(release).build();
} catch (RequestValidatingException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e){
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating application release for the application with the id " + appId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/public-app/{appId}")
@Override
public Response createPubAppRelease(
@PathParam("deviceType") String deviceTypeName,
@PathParam("appId") int appId,
PublicAppReleaseWrapper publicAppReleaseWrapper, @QueryParam("is-published") boolean isPublished) {
try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validatePublicAppReleaseCreatingRequest(publicAppReleaseWrapper, deviceTypeName);
ApplicationRelease applicationRelease = applicationManager.createPubAppRelease(appId, publicAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating application release for the application with the id " + appId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/web-app/{appId}")
@Override
public Response createWebAppRelease(
@PathParam("appId") int appId,
WebAppReleaseWrapper webAppReleaseWrapper, @QueryParam("is-published") boolean isPublished) {
try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateWebAppReleaseCreatingRequest(webAppReleaseWrapper);
ApplicationRelease applicationRelease= applicationManager.createWebAppRelease(appId, webAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating application release for the application with the id " + appId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/custom-app/{appId}")
@Override
public Response createCustomAppRelease(
@PathParam("deviceType") String deviceTypeName,
@PathParam("appId") int appId,
CustomAppReleaseWrapper customAppReleaseWrapper, @QueryParam("is-published") boolean isPublished) {
try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateCustomAppReleaseCreatingRequest(customAppReleaseWrapper, deviceTypeName);
ApplicationRelease release = applicationManager.createCustomAppRelease(appId, customAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(release).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating application release for the application with the id " + appId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@GET
@Path("/device-type/{deviceType}/app-name")
public Response isExistingApplication(
@PathParam("deviceType") String deviceType,
@QueryParam("appName") String appName){
try {
if (appName == null) {
String msg = "Invalid app name, appName query param cannot be empty/null.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
if (appName.length() > 20) {
String msg = "Invalid app name, maximum length of the application name should be 20 characters.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
ApplicationManager applicationManager = APIUtil.getApplicationManager();
if (applicationManager.isExistingAppName(appName, deviceType)) {
String msg = "Invalid app name, app name already exists.";
log.error(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Internal Error occurred while checking the application existence.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/image-artifacts/{uuid}")
public Response updateApplicationImageArtifacts(
@PathParam("uuid") String applicationReleaseUuid,
Base64File iconFile,
Base64File bannerFile,
List<Base64File> screenshots) {
try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(iconFile, screenshots,
null, bannerFile);
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.updateApplicationImageArtifact(applicationReleaseUuid,
artifact);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationReleaseUuid).build();
} catch (NotFoundException e) {
String msg = "Couldn't found an application release which has application release UUID "
+ applicationReleaseUuid + ". Hence please verify the application release UUID again and execute "
+ "the operation";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the application image artifacts for application release uuid: "
+ applicationReleaseUuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/ent-app-artifact/{deviceType}/{uuid}")
public Response updateApplicationArtifact(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationReleaseUuid,
Base64File binaryFile) {
try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.updateApplicationArtifact(deviceType, applicationReleaseUuid,
ApplicationManagementUtil.constructApplicationArtifact(null, null,
binaryFile, null));
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application release. UUID is "
+ applicationReleaseUuid).build();
} catch (RequestValidatingException e) {
String msg =
"Couldn't find the binary file with the request. Hence invoke the API with updating application"
+ " artifact";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application which has application release UUID: " + applicationReleaseUuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found an invalid device type: " + deviceType + " with the request";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the image artifacts of the application with the uuid "
+ applicationReleaseUuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@PUT
@Consumes("application/json")
@Path("/{appId}")
public Response updateApplication(
@PathParam("appId") int applicationId,
@Valid ApplicationUpdateWrapper applicationUpdateWrapper) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
Application application = applicationManager.updateApplication(applicationId, applicationUpdateWrapper);
return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application for application id: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Internal Error occurred while modifying the application.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Path("/ent-app-release/{uuid}")
public Response updateEntAppRelease(
@PathParam("uuid") String applicationUUID,
EntAppReleaseWrapper entAppReleaseWrapper) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(entAppReleaseWrapper.getIcon(),
entAppReleaseWrapper.getScreenshots(), entAppReleaseWrapper.getBinaryFile(), entAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager
.updateEntAppRelease(applicationUUID, entAppReleaseWrapper, artifact);
if (applicationRelease == null) {
String msg ="Ent app release updating is failed. Please contact the administrator. Application release "
+ "UUID: " + applicationUUID;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
String oldPackageName = applicationManager.getApplicationByUuid(applicationUUID).getPackageName();
applicationManager.updateAppIconInfo(applicationRelease, oldPackageName);
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found an ent app or ent app release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the ent app release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the ent app release which has UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Path("/public-app-release/{uuid}")
public Response updatePubAppRelease(
@PathParam("uuid") String applicationUUID,
PublicAppReleaseWrapper publicAppReleaseWrapper) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(publicAppReleaseWrapper.getIcon(),
publicAppReleaseWrapper.getScreenshots(), null, publicAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager
.updatePubAppRelease(applicationUUID, publicAppReleaseWrapper, artifact);
if (applicationRelease == null) {
String msg ="Public app release updating is failed. Please contact the administrator. "
+ "Application release UUID: " + applicationUUID + ", Supported device type:";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
String oldPackageName = applicationManager.getApplicationByUuid(applicationUUID).getPackageName();
applicationManager.updateAppIconInfo(applicationRelease, oldPackageName);
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = "Couldn't found public app or public app release for application release UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the public app release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the public app release which has UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Path("/web-app-release/{uuid}")
public Response updateWebAppRelease(
@PathParam("uuid") String applicationUUID,
WebAppReleaseWrapper webAppReleaseWrapper) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(webAppReleaseWrapper.getIcon(),
webAppReleaseWrapper.getScreenshots(), null, webAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager
.updateWebAppRelease(applicationUUID, webAppReleaseWrapper, artifact);
if (applicationRelease == null) {
String msg ="web app release updating is failed. Please contact the administrator. Application "
+ "release UUID: " + applicationUUID;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = "Couldn't found web app or web app release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the web app release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the web app release which has UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Path("/custom-app-release/{uuid}")
public Response updateCustomAppRelease(
@PathParam("uuid") String applicationUUID,
CustomAppReleaseWrapper customAppReleaseWrapper) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(customAppReleaseWrapper.getIcon(),
customAppReleaseWrapper.getScreenshots(), customAppReleaseWrapper.getBinaryFile(), customAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager
.updateCustomAppRelease(applicationUUID, customAppReleaseWrapper, artifact);
if (applicationRelease == null) {
String msg ="Custom app release updating is failed. Please contact the administrator. Application "
+ "release UUID: " + applicationUUID;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found an ent app or ent app release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the ent app release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the ent app release which has UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Path("/life-cycle/state-changes/{uuid}")
public Response getLifecycleStates(
@PathParam("uuid") String releaseUuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
List<LifecycleState> lifecycleStates = applicationManager.getLifecycleStateChangeFlow(releaseUuid);
return Response.status(Response.Status.OK).entity(lifecycleStates).build();
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + releaseUuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting lifecycle states for application release UUID: " + releaseUuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@POST
@Path("/life-cycle/{uuid}")
public Response addLifecycleState(
@PathParam("uuid") String applicationUuid,
@Valid LifecycleChanger lifecycleChanger) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationRelease applicationRelease = applicationManager
.changeLifecycleState(applicationUuid, lifecycleChanger);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (ForbiddenException e) {
String msg = "You are trying to move the application release into incompatible state for application "
+ "which has application ID: " + applicationUuid;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).build();
} catch (NotFoundException e) {
String msg = "Could,t find application release for application release uuid: " + applicationUuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while adding lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@GET
@Override
@Consumes("application/json")
@Path("/lifecycle-config")
public Response getLifecycleConfig() {
AppmDataHandler dataHandler = APIUtil.getDataHandler();
try {
return Response.status(Response.Status.OK).entity(dataHandler.getLifecycleConfiguration()).build();
} catch (LifecycleManagementException e) {
String msg = "Error Occurred while accessing lifecycle manager.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
@Consumes("application/json")
@Path("/tags")
public Response getTags() {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
List<Tag> tags = applicationManager.getRegisteredTags();
return Response.status(Response.Status.OK).entity(tags).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while getting registered tags.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Override
@Consumes(MediaType.WILDCARD)
@Path("/{appId}/tags/{tagName}")
public Response deleteApplicationTag(
@PathParam("appId") int appId,
@PathParam("tagName") String tagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteApplicationTag(appId, tagName);
String msg = "Tag " + tagName + " is deleted successfully.";
return Response.status(Response.Status.OK).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting registered tag.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Override
@Consumes(MediaType.WILDCARD)
@Path("/tags/{tagName}")
public Response deleteUnusedTag(
@PathParam("tagName") String tagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteUnusedTag(tagName);
String msg = "Tag " + tagName + " is deleted successfully.";
return Response.status(Response.Status.OK).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting unused tag.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@PUT
@Override
@Consumes("application/json")
@Path("/tags/rename")
public Response modifyTagName(
@QueryParam("from") String oldTagName,
@QueryParam("to") String newTagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.updateTag(oldTagName, newTagName);
String msg = "Tag " + oldTagName + " is updated to " + newTagName + " successfully.";
return Response.status(Response.Status.OK).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while updating registered tag.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Override
@Consumes("application/json")
@Path("/tags")
public Response addTags(
List<String> tagNames) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
List<String> tags = applicationManager.addTags(tagNames);
return Response.status(Response.Status.OK).entity(tags).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while adding new tag.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Override
@Consumes("application/json")
@Path("/{appId}/tags")
public Response addApplicationTags(
@PathParam("appId") int appId,
List<String> tagNames) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
List<String> applicationTags = applicationManager.addApplicationTags(appId, tagNames);
return Response.status(Response.Status.OK).entity(applicationTags).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while adding new tags for application which has application ID: " + appId + ".";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
@Consumes("application/json")
@Path("/categories")
public Response getCategories() {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
List<Category> categories = applicationManager.getRegisteredCategories();
return Response.status(Response.Status.OK).entity(categories).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while getting registered categories.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
public <T> Response createApplication(T appWrapper, boolean isPublished) throws ApplicationManagementException, RequestValidatingException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateAppCreatingRequest(appWrapper);
Application application = applicationManager.createApplication(appWrapper, isPublished);
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
} else {
String msg = "Application creation is failed";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,363 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.publisher.api.impl;
import io.entgra.device.mgt.core.application.mgt.common.IdentityServerResponse;
import io.entgra.device.mgt.core.application.mgt.common.SPApplicationListResponse;
import io.entgra.device.mgt.core.application.mgt.common.dto.IdentityServerDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.IdentityServiceProviderDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
import io.entgra.device.mgt.core.application.mgt.common.response.Application;
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.ApplicationWrapper;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.CustomAppWrapper;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.PublicAppWrapper;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppWrapper;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.publisher.api.SPApplicationService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@Produces(MediaType.APPLICATION_JSON)
@Path("/identity-server-applications")
public class SPApplicationServiceImpl implements SPApplicationService {
private static final Log log = LogFactory.getLog(SPApplicationServiceImpl.class);
@Path("/identity-servers/identity-service-providers")
@GET
@Override
public Response getIdentityServiceProviders() {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
try {
List<IdentityServiceProviderDTO> identityServiceProviders = spAppManager.getIdentityServiceProviders();
return Response.status(Response.Status.OK).entity(identityServiceProviders).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting identity service providers";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Path("/identity-servers")
@GET
@Override
public Response getIdentityServers() {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
List<IdentityServerResponse> identityServers = spAppManager.getIdentityServers();
return Response.status(Response.Status.OK).entity(identityServers).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@Path("/identity-servers/{id}")
@DELETE
@Override
public Response deleteIdentityServer(@PathParam("id") int id) {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
spAppManager.deleteIdentityServer(id);
return Response.status(Response.Status.OK).entity("Successfully deleted identity server").build();
} catch (NotFoundException e) {
String msg = "Identity server with the id " + id + " does not exist.";
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@Path("/identity-servers/{id}")
@GET
@Override
public Response getIdentityServer(@PathParam("id") int id) {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
IdentityServerResponse identityServer = spAppManager.getIdentityServerResponse(id);
return Response.status(Response.Status.OK).entity(identityServer).build();
} catch (NotFoundException e) {
String msg = "Identity server with the id " + id + " does not exist.";
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@Path("/identity-servers/{id}")
@PUT
@Override
public Response updateIdentityServer(IdentityServerDTO identityServerDTO, @PathParam("id") int id) {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
IdentityServerResponse identityServerResponse = spAppManager.updateIdentityServer(identityServerDTO, id);
return Response.status(Response.Status.OK).entity(identityServerResponse).build();
} catch (NotFoundException e) {
String msg = "Identity server with the id " + id + " does not exist.";
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String errMsg = e.getMessage();
log.error(errMsg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@Path("/identity-servers")
@POST
@Override
public Response createIdentityServer(IdentityServerDTO identityServerDTO) {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
IdentityServerResponse identityServer = spAppManager.createIdentityServer(identityServerDTO);
return Response.status(Response.Status.CREATED).entity(identityServer).build();
} catch (BadRequestException e) {
String errMsg = e.getMessage();
log.error(errMsg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@GET
@Path("/identity-servers/identity-server-name")
@Override
public Response isIdentityServerNameExists(
@QueryParam("identityServerName") String identityServerName) {
try {
if (identityServerName == null) {
String msg = "Invalid identity server name, identityServerName query param cannot be empty/null.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build();
}
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
if (spAppManager.isIdentityServerNameExist(identityServerName)) {
return Response.status(Response.Status.CONFLICT).build();
}
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String errMsg = "Identity server request payload is invalid";
log.error(errMsg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@GET
@Path("/identity-servers/identity-server-url")
@Override
public Response isIdentityServerUrlExists(
@QueryParam("identityServerUrl") String identityServerUrl) {
try {
if (identityServerUrl == null) {
String msg = "Invalid identity server url, identityServerName query param cannot be empty/null.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build();
}
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
if (spAppManager.isIdentityServerUrlExist(identityServerUrl)) {
return Response.status(Response.Status.CONFLICT).build();
}
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String errMsg = "Identity server request payload is invalid";
log.error(errMsg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@Path("/{identity-server-id}/service-providers")
@GET
@Override
public Response getServiceProviders(@DefaultValue("30") @QueryParam("limit") Integer limit,@DefaultValue("0") @QueryParam("offset") Integer offset,
@PathParam("identity-server-id") int identityServerId) {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
SPApplicationListResponse applications = spAppManager.retrieveSPApplicationFromIdentityServer(identityServerId, limit, offset);
return Response.status(Response.Status.OK).entity(applications).build();
} catch (NotFoundException e) {
String errMsg = "No Identity server exist with the id: " + identityServerId;
log.error(errMsg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
}
}
@Path("/{identity-server-id}/service-provider/{service-provider-id}/attach")
@POST
@Override
public Response attachApps(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds) {
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
try {
spApplicationManager.validateAttachAppsRequest(identityServerId, serviceProviderId, appIds);
spApplicationManager.attachSPApplications(identityServerId, serviceProviderId, appIds);
} catch (NotFoundException e) {
String msg = "No identity server exist with the id " + identityServerId;
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid appIds provided";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while attaching apps to service provider with the id" + serviceProviderId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).build();
}
@Path("/{identity-server-id}/service-provider/{service-provider-id}/detach")
@POST
@Override
public Response detachApps(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds) {
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
try {
spApplicationManager.validateDetachAppsRequest(identityServerId, serviceProviderId, appIds);
spApplicationManager.detachSPApplications(identityServerId, serviceProviderId, appIds);
} catch (NotFoundException e) {
String msg = "No identity server exist with the id " + identityServerId;
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid appIds provided";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while attaching apps to service provider with the id" + serviceProviderId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).build();
}
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/ent-app")
@POST
@Override
public Response createEntApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app,
@QueryParam("is-published") boolean isPublished) {
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
}
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/public-app")
@POST
@Override
public Response createPubApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app,
@QueryParam("is-published") boolean isPublished) {
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
}
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
@POST
@Override
public Response createWebApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app,
@QueryParam("is-published") boolean isPublished) {
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
}
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
@POST
@Override
public Response createCustomApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app,
@QueryParam("is-published") boolean isPublished) {
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
}
/**
* Validates and creates service provider application
*
* @param identityServerId id of the identity server
* @param spUID uid of the service provider
* @param appWrapper application wrapper
* @param <T> application wrapper class
* @return Response
*/
private <T> Response createSPApplication(int identityServerId, String spUID, T appWrapper, boolean isPublished) {
try {
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
Application createdApp = spApplicationManager.createSPApplication(appWrapper, identityServerId, spUID, isPublished);
return Response.status(Response.Status.CREATED).entity(createdApp).build();
} catch (NotFoundException e) {
String msg = "No identity server exist with the id " + identityServerId;
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found incompatible payload with create service provider app request.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Found invalid release payload with create service provider app request.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
catch (ApplicationManagementException e) {
String msg = "Error occurred while creating service provider app";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,216 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.publisher.api.impl.admin;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.publisher.api.admin.ApplicationManagementPublisherAdminAPI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* Implementation of Application Management related APIs.
*/
@Produces({"application/json"})
@Path("/admin/applications")
public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationManagementPublisherAdminAPI {
private static final Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class);
@DELETE
@Consumes(MediaType.WILDCARD)
@Path("/release/{uuid}")
public Response deleteApplicationRelease(
@PathParam("uuid") String releaseUuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteApplicationRelease(releaseUuid);
return Response.status(Response.Status.OK)
.entity("Successfully deleted the application release for uuid: " + releaseUuid).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found application release which is having application release UUID:" + releaseUuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to delete the application release which has UUID "
+ releaseUuid;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application release for application release UUID:: "
+ releaseUuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Consumes(MediaType.WILDCARD)
@Path("/{appId}")
public Response deleteApplication(
@PathParam("appId") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteApplication(applicationId);
return Response.status(Response.Status.OK)
.entity("Successfully deleted the application which has ID: " + applicationId).build();
} catch (NotFoundException e) {
String msg = "Couldn't found application release which is having the ID:" + applicationId;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to delete the application which has ID: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application which has application ID:: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Override
@Consumes(MediaType.WILDCARD)
@Path("/tags")
public Response deleteTag(
@QueryParam("tag-name") String tagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteTag(tagName);
return Response.status(Response.Status.OK).entity("Tag " + tagName + " is deleted successfully.").build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting registered tag.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Override
@Consumes("application/json")
@Path("/categories")
public Response addCategories(
List<String> categoryNames) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
List<String> categories = applicationManager.addCategories(categoryNames);
return Response.status(Response.Status.OK).entity(categories).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while adding new categories.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@PUT
@Override
@Consumes("application/json")
@Path("/categories/rename")
public Response renameCategory(
@QueryParam("from") String oldCategoryName,
@QueryParam("to") String newCategoryName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.updateCategory(oldCategoryName, newCategoryName);
return Response.status(Response.Status.OK)
.entity("Category is updated from " + oldCategoryName + " to " + newCategoryName).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while rename registered category.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Override
@Consumes(MediaType.WILDCARD)
@Path("/categories")
public Response deleteCategory(
@QueryParam("category-name") String categoryName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteCategory(categoryName);
return Response.status(Response.Status.OK).entity("Category " + categoryName + " is deleted successfully.")
.build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting registered category.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@PUT
@Path("/retire/{appId}")
public Response retireApplication(
@PathParam("appId") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.retireApplication(applicationId);
return Response.status(Response.Status.OK)
.entity("Successfully retired the application which has application ID: " + applicationId).build();
} catch (NotFoundException e) {
String msg = "Couldn't found application for application id: " + applicationId + " to delete the "
+ "application";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to delete the application which has ID " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,111 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.publisher.api.impl.admin;
import io.entgra.device.mgt.core.application.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.application.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.application.mgt.common.Rating;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.ReviewManagementException;
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.publisher.api.admin.ReviewManagementPublisherAdminAPI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
/**
* Review Management related jax-rs APIs.
*/
@Path("/admin/reviews")
public class ReviewManagementPublisherAdminAPIImpl implements ReviewManagementPublisherAdminAPI {
private static final Log log = LogFactory.getLog(ReviewManagementPublisherAdminAPIImpl.class);
@Override
@GET
@Path("/release/{uuid}")
public Response getAllReleaseReviews(
@PathParam("uuid") String uuid,
@DefaultValue("0") @QueryParam("offset") int offSet,
@DefaultValue("20") @QueryParam("limit") int limit) {
ReviewManager reviewManager = APIUtil.getReviewManager();
PaginationRequest request = new PaginationRequest(offSet, limit);
try {
PaginationResult paginationResult = reviewManager.getAllReleaseReviews(request, uuid);
return Response.status(Response.Status.OK).entity(paginationResult).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException e) {
String msg = "Error occurred while retrieving reviews for application UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while retrieving application release details for application UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@GET
@Path("/{uuid}/release-rating")
public Response getAppReleaseRating(
@PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager();
Rating rating;
try {
rating = reviewManager.getAppReleaseRating(uuid);
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException | ApplicationManagementException e) {
String msg = "Error occured while getting review data for application release UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
return Response.status(Response.Status.OK).entity(rating).build();
}
@Override
@GET
@Path("/{uuid}/app-rating")
public Response getAppRating(
@PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager();
Rating rating;
try {
rating = reviewManager.getAppRating(uuid);
} catch (NotFoundException e) {
String msg = "Couldn't found an application for application release UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException | ApplicationManagementException e) {
String msg = "Error occured while getting review data for application release UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
return Response.status(Response.Status.OK).entity(rating).build();
}
}

@ -1,65 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<!-- 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>
<!-- ApplicationDTO related permissions -->
<Permission>
<name>Get Application Details</name>
<path>/device-mgt/application/get</path>
<url>/application-mgt/applications</url>
<method>GET</method>
</Permission>
<Permission>
<name>Create an Application</name>
<path>/device-mgt/application/create</path>
<url>/application-mgt/applications</url>
<method>POST</method>
</Permission>
<Permission>
<name>Update an Application</name>
<path>/device-mgt/application/update</path>
<url>/application-mgt/applications</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Login to Application Management</name>
<path>/device-mgt/application-mgt/login</path>
<url>/application-mgt/applications</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Delete an Application</name>
<path>device-mgt/application/delete</path>
<url>/application-mgt/applications/*</url>
<method>DELETE</method>
</Permission>
</PermissionConfiguration>

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<!--
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>CXF3,Carbon</Environments>
</Classloading>

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
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 http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<jaxrs:server id="applicationMgtService" address="/">
<jaxrs:serviceBeans>
<ref bean="identityServerApplicationMgtServiceBean"/>
<ref bean="applicationMgtServiceBean"/>
<ref bean="reviewMgtAdminServiceBean"/>
<ref bean="applicationMgtAdminServiceBean"/>
<ref bean="swaggerResource"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="multipartProvider"/>
<ref bean="swaggerWriter"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="io.entgra.device.mgt.core.application.mgt.publisher.api"/>
<property name="version" value="1.0"/>
<property name="host" value="localhost:9443"/>
<property name="schemes" value="https" />
<property name="basePath" value="/api/application-mgt-publisher/v1.0"/>
<property name="title" value="Application Management Publisher API Definitions"/>
<property name="contact" value="bizdev-group@entgra.io"/>
<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="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor" class="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor"/>
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="identityServerApplicationMgtServiceBean" class="io.entgra.device.mgt.core.application.mgt.publisher.api.impl.SPApplicationServiceImpl"/>
<bean id="applicationMgtServiceBean" class="io.entgra.device.mgt.core.application.mgt.publisher.api.impl.ApplicationManagementPublisherAPIImpl"/>
<bean id="applicationMgtAdminServiceBean" class="io.entgra.device.mgt.core.application.mgt.publisher.api.impl.admin.ApplicationManagementPublisherAdminAPIImpl"/>
<bean id="reviewMgtAdminServiceBean" class="io.entgra.device.mgt.core.application.mgt.publisher.api.impl.admin.ReviewManagementPublisherAdminAPIImpl" />
<bean id="jsonProvider" class="io.entgra.device.mgt.core.application.mgt.addons.JSONMessageHandler"/>
<bean id="multipartProvider" class="io.entgra.device.mgt.core.application.mgt.addons.MultipartCustomProvider"/>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor"/>
</cxf:inInterceptors>
</cxf:bus>
</beans>

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>Application Management Webapp</display-name>
<servlet>
<description>JAX-WS/JAX-RS Application 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>
<!-- configure a security filter -->
<init-param>
<param-name>swagger.security.filter</param-name>
<param-value>ApiAuthorizationFilterImpl</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</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>doAuthentication</param-name>
<param-value>true</param-value>
</context-param>
<!-- Below configuration is used to redirect http requests to https -->
<security-constraint>
<web-resource-collection>
<web-resource-name>ApplicationMgt-Admin</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!--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>
<context-param>
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>io.entgra.device.mgt.core.application.mgt.addons.ApiOriginFilter</filter-class>
</filter>
<filter>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class>
<init-param>
<param-name>patterns</param-name>
<param-value>text/html" ,application/json" ,text/plain</param-value>
</init-param>
<init-param>
<param-name>filterAction</param-name>
<param-value>enforce</param-value>
</init-param>
<init-param>
<param-name>httpHeaders</param-name>
<param-value>Cache-Control: no-store, no-cache, must-revalidate, private</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -1,241 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>application-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.application.mgt.store.api</artifactId>
<packaging>war</packaging>
<name>Entgra - Application Management Store API</name>
<description>Entgra - Application Management Store API</description>
<url>https://entgra.io</url>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#application-mgt-store#v1.0</warName>
</configuration>
</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>
<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="api#application-mgt-store#v1.0.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>
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</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.utils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.addons</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.device.mgt.common</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>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -1,61 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* This is used to map the status of subscription.
*/
@ApiModel(
value = "SubscriptionStatusBean",
description = "This class carries all information related map statuses of the subscription."
)
public class SubscriptionStatusBean {
@ApiModelProperty(
name = "sub id",
value = "Subscription Id.",
required = true
)
private int subId;
@ApiModelProperty(
name = "status",
value = "Status of the subscription.",
required = true
)
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getSubId() {
return subId;
}
public void setSubId(int subId) {
this.subId = subId;
}
}

@ -1,271 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.entgra.device.mgt.core.application.mgt.common.Filter;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.swagger.annotations.*;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* APIs to handle application storage management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Application Storage Management Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ApplicationStorageManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/applications"),
})
}
),
tags = {
@Tag(name = "application_management, device_management", description = "ApplicationDTO Storage Management "
+ "related APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Get Application Details",
description = "Get application details",
key = "perm:app:store:view",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/store/application/view"}
),
@Scope(
name = "Modify Application",
description = "Modify application state",
key = "perm:app:store:modify",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/store/application/modify"}
)
}
)
@Path("/applications")
@Api(value = "Application Management", description = "This API carries all app store management related operations such"
+ " as get all the applications etc.")
@Produces(MediaType.APPLICATION_JSON)
public interface ApplicationManagementAPI {
String SCOPE = "scope";
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/favourite/{appId}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "add application to favourites",
notes = "This will add application to favourites",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:store:modify")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully added application to favourites.",
response = ApplicationList.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Payload contains unacceptable or vulnerable data"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while adding the application to favourites.",
response = ErrorResponse.class)
})
Response addAppToFavourite(
@ApiParam(
name = "appId",
value = "id of the application",
required = true)
@PathParam("appId") int appId);
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("/favourite/{appId}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "remove application from favourites",
notes = "This will removing an application from favourites",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:store:modify")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully removed application from favourites.",
response = ApplicationList.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Payload contains unacceptable or vulnerable data"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while removing the application from favourites.",
response = ErrorResponse.class)
})
Response removeAppFromFavourite(
@ApiParam(
name = "appId",
value = "id of the application",
required = true)
@PathParam("appId") int appId);
@POST
@Path("/favourite")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get all favourite applications",
notes = "This will get all favourite applications",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:store:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully got application list.",
response = ApplicationList.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Application retrieving request payload contains unacceptable or vulnerable data"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class)
})
Response getFavouriteApplications(
@ApiParam(
name = "filter",
value = "Application filtering data",
required = true)
@Valid Filter filter);
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get all applications",
notes = "This will get all applications",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:store:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully got application list.",
response = ApplicationList.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Application retrieving request payload contains unacceptable or vulnerable data"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class)
})
Response getApplications(
@ApiParam(
name = "filter",
value = "Application filtering data",
required = true)
@Valid Filter filter
);
@GET
@Path("/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get the application of requesting application type",
notes = "This will get the application identified by the application type and name, if exists",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:store:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved relevant application.",
response = ApplicationDTO.class),
@ApiResponse(
code = 404,
message = "Application not found"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting relevant application.",
response = ErrorResponse.class)
})
Response getApplication(
@ApiParam(
name = "uuid",
value = "Type of the application",
required = true)
@PathParam("uuid") String uuid
);
}

@ -1,420 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.entgra.device.mgt.core.application.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.application.mgt.common.response.Review;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.ReviewWrapper;
import io.swagger.annotations.*;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* APIs to handle review management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Review Management Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ReviewManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/reviews"),
})
}
),
tags = {
@Tag(name = "review_management", description = "Review Management related APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Get Review Details",
description = "Get review details from application store.",
key = "perm:app:review:view",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/store/review/view"}
),
@Scope(
name = "Update a Review",
description = "Update a Review from the application store.",
key = "perm:app:review:update",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/store/review/update"}
),
}
)
@Path("/reviews")
@Api(value = "Review Management API")
@Produces(MediaType.APPLICATION_JSON)
public interface ReviewManagementAPI {
String SCOPE = "scope";
@GET
@Path("/app/user/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get app reviews",
notes = "Get all app reviews",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:review:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved app reviews.",
response = PaginationResult.class,
responseContainer = "PaginationResult"),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release associated with requested "
+ "UUID."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the review list.",
response = ErrorResponse.class)
})
Response getUserReviews(
@ApiParam(
name="uuid",
value="uuid of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name="offset",
value="Starting review number.",
defaultValue = "0")
@QueryParam("offSet") int offSet,
@ApiParam(
name="limit",
value = "Limit of paginated reviews",
defaultValue = "20")
@QueryParam("limit") int limit);
@GET
@Path("/app/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get app reviews",
notes = "Get all app reviews",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:review:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved app reviews.",
response = PaginationResult.class,
responseContainer = "PaginationResult"),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release associated with requested "
+ "UUID."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the review list.",
response = ErrorResponse.class)
})
Response getAllAppReviews(
@ApiParam(
name="uuid",
value="uuid of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name="offset",
value="Starting review number.",
defaultValue = "0")
@QueryParam("offSet") int offSet,
@ApiParam(
name="limit",
value = "Limit of paginated reviews",
defaultValue = "20")
@QueryParam("limit") int limit);
@POST
@Path("/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add a review",
notes = "This will add a new review for application release.",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully add a reviewTmp.",
response = Review.class),
@ApiResponse(
code = 400,
message =
"Bad Request. \n Found invalid payload with the request."),
@ApiResponse(
code = 403,
message = "Don't have permission to add a review."),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release for requested UUID."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred adding a reviewTmp.",
response = ErrorResponse.class)
})
Response addReview(
@ApiParam(
name = "reviewTmp",
value = "Review details",
required = true) ReviewWrapper reviewWrapper,
@ApiParam(
name="uuid",
value="uuid of the application release.",
required=true)
@PathParam("uuid") String uuid);
@POST
@Path("/{uuid}/{parentReviewId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add a reply comment",
notes = "This will add a reply comment for a comment or review.",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully add a reviewTmp.",
response = Review.class),
@ApiResponse(
code = 400,
message =
"Bad Request. \n Found invalid payload with the request."),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release for requested UUID."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred adding a reviewTmp.",
response = ErrorResponse.class)
})
Response addReplyComment(
@ApiParam(
name = "review",
value = "Reply comment details",
required = true) ReviewWrapper reviewWrapper,
@ApiParam(
name="uuid",
value="uuid of the application release.",
required=true)
@PathParam("uuid") String uuid,
@ApiParam(
name="parentReviewId",
value="uuid of the application release.",
required=true)
@PathParam("parentReviewId") int parentReviewId);
@PUT
@Path("/{uuid}/{reviewId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Edit a reviewTmp",
notes = "This will edit the reviewTmp",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully updated reviewTmp.",
response = Review.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while updating the new reviewTmp.",
response = ErrorResponse.class)
})
Response updateReview(
@ApiParam(
name = "reviewTmp",
value = "The reviewTmp that need to be updated.",
required = true)
@Valid ReviewWrapper updatingReview,
@ApiParam(
name="uuid",
value = "uuid of the application release",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name="reviewId",
value = "reviewTmp id of the updating reviewTmp.",
required = true)
@PathParam("reviewId") int reviewId);
@DELETE
@Path("/{uuid}/{reviewId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Remove comment",
notes = "Remove comment",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
})
},
nickname = "deleteReviewComment"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the review"),
@ApiResponse(
code = 403,
message = "Don't have permission to delete the review."),
@ApiResponse(
code = 404,
message = "Not Found. \n No activity found with the given ID.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting the review.",
response = ErrorResponse.class)
})
Response deleteReview(
@ApiParam(
name="uuid",
value="UUID of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name="reviewId",
value="Id of the review.",
required = true)
@PathParam("reviewId") int reviewId);
@GET
@Path("/{uuid}/app-rating")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get app ratings",
notes = "Get all app ratings",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:review:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved ratings.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Application found which has application release of UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting ratings",
response = ErrorResponse.class)
})
Response getAppRating(
@ApiParam(
name = "uuid",
value = "uuid of the application release",
required = true)
@PathParam("uuid")
String uuid);
}

@ -1,556 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.swagger.annotations.*;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* API to handle subscription management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Subscription Management Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "SubscriptionManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/subscription"),
})
}
),
tags = {
@Tag(name = "subscription_management, device_management", description = "Subscription Management "
+ "related APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Install an ApplicationDTO",
description = "Install an application",
key = "perm:app:subscription:install",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/store/subscription/install"}
),
@Scope(
name = "Uninstall an Application",
description = "Uninstall an application",
key = "perm:app:subscription:uninstall",
roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/store/subscription/uninstall"}
)
}
)
@Path("/subscription")
@Api(value = "Subscription Management")
@Produces(MediaType.APPLICATION_JSON)
public interface SubscriptionManagementAPI {
String SCOPE = "scope";
@POST
@Path("/{uuid}/devices/{action}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Install an application for devices",
notes = "This will install an application to a given list of devices",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install")
})
}
)
@ApiResponses(
value = {
})
Response performAppOperationForDevices(
@ApiParam(
name = "uuid",
value = "The application ID and list of devices/users/roles",
required = true
)
@PathParam("uuid") String uuid,
@ApiParam(
name = "action",
value = "Performing action.",
required = true
)
@PathParam("action") String action,
@ApiParam(
name = "deviceIdentifiers",
value = "The list of device identifiers",
required = true
)
@Valid List<DeviceIdentifier> deviceIdentifiers,
@ApiParam(
name = "timestamp",
value = "Timestamp of scheduled install/uninstall operation"
)
@QueryParam("timestamp") long timestamp,
@ApiParam(
name = "block-uninstall",
value = "App removal status of the install operation"
)
@QueryParam("block-uninstall") Boolean isUninstallBlocked
);
@POST
@Path("/{uuid}/{subType}/{action}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Install an application for subscription type.",
notes = "This will install an application to a given subscription type and this is bulk app installation.",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install")
})
}
)
@ApiResponses(
value = {
})
Response performBulkAppOperation(
@ApiParam(
name = "uuid",
value = "The application release UUID",
required = true
)
@PathParam("uuid") String uuid,
@ApiParam(
name = "subType",
value = "Subscription type of the app installing operation.",
required = true
)
@PathParam("subType") String subType,
@ApiParam(
name = "action",
value = "Performing action.",
required = true
)
@PathParam("action") String action,
@ApiParam(
name = "subscribers",
value = "Subscriber list of the application release.",
required = true
)
@Valid List<String> subscribers,
@ApiParam(
name = "timestamp",
value = "Timestamp of scheduled install/uninstall operation"
)
@QueryParam("timestamp") long timestamp,
@ApiParam(
name = "block-uninstall",
value = "App removal status of the install operation"
)
@QueryParam("block-uninstall") Boolean isUninstallBlocked,
@ApiParam(
name = "disable-operation-re-executing",
value = "Disable Operation re-executing"
)
@QueryParam("disable-operation-re-executing") boolean isOperationReExecutingDisabled
);
@POST
@Path("/{uuid}/devices/ent-app-install/{action}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Install an application for devices via google enterprise app installing service",
notes = "This will install an application to a given list of devices",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install")
})
}
)
@ApiResponses(
value = {
})
Response performEntAppSubscriptionOnDevices(
@ApiParam(
name = "uuid",
value = "The application UUID",
required = true
)
@PathParam("uuid") String uuid,
@ApiParam(
name = "action",
value = "Performing action.",
required = true
)
@PathParam("action") String action,
@ApiParam(
name = "deviceIdentifiers",
value = "The list of device identifiers",
required = true
)
@Valid List<DeviceIdentifier> deviceIdentifiers,
@ApiParam(
name = "timestamp",
value = "Timestamp of scheduled ent. install operation"
)
@QueryParam("timestamp") long timestamp,
@ApiParam(
name = "requiresUpdatingExternal",
value = "Should external system such as Google EMM APIs need to be updated."
)
@QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal
);
@POST
@Path("/{uuid}/{subType}/ent-app-install/{action}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Install an application for subscription type via google enterprise install.",
notes = "This will install an application to a given subscription type and this is bulk app installation.",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install")
})
}
)
@ApiResponses(
value = {
})
Response performBulkEntAppSubscription(
@ApiParam(
name = "uuid",
value = "The application release UUID",
required = true
)
@PathParam("uuid") String uuid,
@ApiParam(
name = "subType",
value = "Subscription type of the app installing operation.",
required = true
)
@PathParam("subType") String subType,
@ApiParam(
name = "action",
value = "Performing action.",
required = true
)
@PathParam("action") String action,
@ApiParam(
name = "subscribers",
value = "Subscriber list of the application release.",
required = true
)
@Valid List<String> subscribers,
@ApiParam(
name = "timestamp",
value = "Timestamp of scheduled ent app install operation"
)
@QueryParam("timestamp") long timestamp,
@ApiParam(
name = "requiresUpdatingExternal",
value = "Should external system such as Google EMM APIs need to be updated."
)
@QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal
);
@GET
@Path("/{uuid}/devices")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get device details that have a given application install",
notes = "This will get the device details that have a given application install, if exists",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:uninstall")
})
},
nickname = "getAppInstalledDevicesByUUID"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved device details.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Application found which has application release of UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n Found invalid payload with the request.",
response = List.class),
@ApiResponse(
code = 403,
message = "Forbidden. \n Don't have permission to get the details.",
response = List.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting data",
response = ErrorResponse.class)
})
Response getAppInstalledDevices(
@ApiParam(
name = "name",
value = "The device name. For example, Nexus devices can have names, suhc as shamu, bullhead or angler.",
required = false)
@Size(max = 45)
String name,
@ApiParam(
name = "user",
value = "The username of the owner of the device.",
required = false)
@QueryParam("user")
String user,
@ApiParam(
name = "ownership",
allowableValues = "BYOD, COPE",
value = "Provide the ownership status of the device. The following values can be assigned:\n" +
"- BYOD: Bring Your Own Device\n" +
"- COPE: Corporate-Owned, Personally-Enabled",
required = false)
@QueryParam("ownership")
@Size(max = 45)
String ownership,
@ApiParam(
name = "serialNumber",
value = "The serial number of the device.",
required = false)
@QueryParam("serialNumber")
String serialNumber,
@ApiParam(
name="uuid",
value="uuid of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name = "offset",
value = "The starting pagination index for the complete list of qualified items.",
defaultValue = "0")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Provide how many device details you require from the starting pagination index/offset.",
defaultValue = "5")
@QueryParam("limit") int limit,
@ApiParam(
name = "status",
value = "Provide the device status details, such as active or inactive.")
@QueryParam("status") List<String> status
);
@GET
@Path("/{uuid}/{subType}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get category details that have a given application install",
notes = "This will get the category details that have a given application install, if exists",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:uninstall")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved categories details.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Application found which has application " +
"release of UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n Found invalid payload with the request.",
response = List.class),
@ApiResponse(
code = 403,
message = "Forbidden. \n Don't have permission to get the details.",
response = List.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting data",
response = ErrorResponse.class)
})
Response getAppInstalledCategories(
@ApiParam(
name="uuid",
value="uuid of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name="subType",
value="Subscription type of the application release.",
required = true)
@PathParam("subType") String subType,
@ApiParam(
name = "offset",
value = "The starting pagination index for the complete list of qualified items.",
defaultValue = "0")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Provide how many device details you require from the starting " +
"pagination index/offset.",
defaultValue = "5")
@QueryParam("limit") int limit
);
@GET
@Path("/{uuid}/{subType}/{subTypeName}/devices")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get device details in categories that have a given application install",
notes = "This will get the category's device details that have a given application install, if exists",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:uninstall")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved device details.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Devices found which has application " +
"release of UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n Found invalid payload with the request.",
response = List.class),
@ApiResponse(
code = 403,
message = "Forbidden. \n Don't have permission to get the details.",
response = List.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting data",
response = ErrorResponse.class)
})
Response getAppInstalledDevicesOnCategories(
@ApiParam(
name="uuid",
value="uuid of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name="subType",
value="Subscription type of the application release.",
required = true)
@PathParam("subType") String subType,
@ApiParam(
name="subTypeName",
value="Subscription type name of the application release.",
required = true)
@PathParam("subTypeName") String subTypeName,
@ApiParam(
name = "offset",
value = "The starting pagination index for the complete list of qualified items.",
defaultValue = "0")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Provide how many device details you require from the starting " +
"pagination index/offset.",
defaultValue = "5")
@QueryParam("limit") int limit,
@ApiParam(
name = "name",
value = "The device name. For example, Nexus devices can have names, such as shamu, bullhead or angler.",
required = false)
@Size(max = 45)
String name,
@ApiParam(
name = "user",
value = "The username of the owner of the device.",
required = false)
@QueryParam("user")
String user,
@ApiParam(
name = "ownership",
allowableValues = "BYOD, COPE",
value = "Provide the ownership status of the device. The following values can be assigned:\n" +
"- BYOD: Bring Your Own Device\n" +
"- COPE: Corporate-Owned, Personally-Enabled",
required = false)
@QueryParam("ownership")
@Size(max = 45)
String ownership,
@ApiParam(
name = "status",
value = "Provide the device status details, such as active or inactive.")
@QueryParam("status") List<String> status
);
}

@ -1,109 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.admin;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.swagger.annotations.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* APIs to handle admin review management related tasks in store.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Store Review Management Admin Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "StoreReviewManagementAdminService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/admin/reviews"),
})
}
),
tags = {
@Tag(name = "review_management", description = "Store Review Management related Admin APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Update a Review",
description = "Update a Review of applications.",
key = "perm:admin:app:review:update",
roles = {"Internal/devicemgt-admin"},
permissions = {"/app-mgt/store/admin/review/update"}
)
}
)
@Path("/admin/reviews")
@Api(value = "Store Review Management Admin API")
public interface ReviewManagementStoreAdminAPI {
String SCOPE = "scope";
@DELETE
@Path("/{uuid}/{reviewId}")
@Produces(MediaType.WILDCARD)
@Consumes(MediaType.WILDCARD)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Remove review",
notes = "Remove review",
tags = "Review Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the review"),
@ApiResponse(
code = 404,
message = "Not Found. \n No activity found with the given ID.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting the review.",
response = ErrorResponse.class)
})
Response deleteReview(
@ApiParam(
name = "uuid",
value = "UUID of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name = "reviewId",
value = "Id of the review.",
required = true)
@PathParam("reviewId") int reviewId);
}

@ -1,201 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.admin;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.application.mgt.common.ErrorResponse;
import io.entgra.device.mgt.core.application.mgt.store.api.beans.SubscriptionStatusBean;
import io.swagger.annotations.*;
import javax.validation.constraints.Size;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* API to handle subscription management related admin tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Subscription Management Admin Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "SubscriptionManagementAdminService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/admin/subscription"),
})
}
),
tags = {
@Tag(name = "subscription_management, device_management", description = "Subscription Management "
+ "related Admin APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "View Application Subscriptions",
description = "View Application Subscriptions.",
key = "perm:admin:app:subscription:view",
roles = {"Internal/devicemgt-admin"},
permissions = {"/app-mgt/store/admin/subscription/view"}
),
@Scope(
name = "View Application Subscriptions",
description = "View Application Subscriptions.",
key = "perm:admin:app:subscription:modify",
roles = {"Internal/devicemgt-admin"},
permissions = {"/app-mgt/store/admin/subscription/modify"}
)
}
)
@Path("/admin/subscription")
@Api(value = "Subscription Management Admin API")
@Produces(MediaType.APPLICATION_JSON)
public interface SubscriptionManagementAdminAPI {
String SCOPE = "scope";
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/device/{deviceId}/status")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Update subscription status",
notes = "This will update the subscription status that belongs to the given device id",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:subscription:modify")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully updated subscription status.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Application found which has application release of UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while updating subscription status",
response = ErrorResponse.class)
})
Response updateSubscription(
@ApiParam(
name = "deviceId",
value = "Id of the device",
required = true)
@PathParam("deviceId") int deviceId,
@ApiParam(
name = "subscription status change bean",
value = "this bean contains the information related to status change",
required = true)
SubscriptionStatusBean subscriptionStatusBean
);
@GET
@Path("/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get subscription details of specific application.",
notes = "This will get the subscription details of specific application",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:subscription:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved subscription details.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No Application found which has application release of UUID.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting data",
response = ErrorResponse.class)
})
Response getAppInstalledDevices(
@ApiParam(
name = "name",
value = "The device name. For example, Nexus devices can have names, suhc as shamu, bullhead or angler.",
required = false)
@Size(max = 45)
String name,
@ApiParam(
name = "user",
value = "The username of the owner of the device.",
required = false)
@QueryParam("user")
String user,
@ApiParam(
name = "action",
value = "The action, subscribed or unsubscribed.",
required = false)
@Size(max = 45)
@QueryParam("action") String action,
@ApiParam(
name = "actionStatus",
value = "Provide the action status details")
@QueryParam("actionStatus") String actionStatus,
@ApiParam(
name = "status",
value = "Provide the device status details, such as active or inactive.")
@QueryParam("status") List<String> status,
@ApiParam(
name = "installedVersion",
value = "Provide the installed version of the application.")
@QueryParam("installedVersion") String installedVersion,
@ApiParam(
name = "uuid",
value = "uuid of the application release.",
required = true)
@PathParam("uuid") String uuid,
@ApiParam(
name = "offset",
value = "The starting pagination index for the complete list of qualified items.",
defaultValue = "0")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Provide how many device details you require from the starting pagination index/offset.",
defaultValue = "5")
@QueryParam("limit") int limit
);
}

@ -1,173 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.impl;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
import io.entgra.device.mgt.core.application.mgt.common.Filter;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.response.Application;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.store.api.services.ApplicationManagementAPI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* Implementation of Application Management STORE APIs.
*/
@Produces({ "application/json" })
@Path("/applications")
public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static final Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
@POST
@Path("/favourite/{appId}")
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Response addAppToFavourite(@PathParam("appId") int appId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.addAppToFavourites(appId);
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while adding application to favourites";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Path("/favourite/{appId}")
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Response removeAppFromFavourite(@PathParam("appId") int appId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.removeAppFromFavourites(appId);
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while removing application from favourites";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Path("/favourite")
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Response getFavouriteApplications(@Valid Filter filter) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
validateFilter(filter);
ApplicationList applications = applicationManager.getFavouriteApplications(filter);
return Response.status(Response.Status.OK).entity(applications).build();
} catch (BadRequestException e) {
String msg = "Invalid filter payload found in the request. Hence verify the filter payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while retrieving favourite applications";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Override
@Consumes("application/json")
public Response getApplications(@Valid Filter filter) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
validateFilter(filter);
filter.setAppReleaseState(applicationManager.getInstallableLifecycleState());
ApplicationList applications = applicationManager.getApplications(filter);
return Response.status(Response.Status.OK).entity(applications).build();
} catch (BadRequestException e) {
String msg = "Invalid request payload found in the request. Hence verify the payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (UnexpectedServerErrorException e) {
String msg = "Unexpected Error occurred while retrieving applications";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while retrieving applications";
log.error(msg);
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Consumes("application/json")
@Path("/{uuid}")
public Response getApplication(@PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
Application application = applicationManager
.getApplicationByUuid(uuid, applicationManager.getInstallableLifecycleState());
if (application == null) {
String msg = "Could not found an application release which is in " + applicationManager
.getInstallableLifecycleState() + " state.";
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application with the application release uuid: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
/**
* This method can be used to check & validate if {@link Filter} object exist.
*
* @param filter {@link Filter}
* @throws BadRequestException if filter object doesn't exist
*/
private void validateFilter(Filter filter) throws BadRequestException {
if (filter == null) {
String msg = "Request Payload is null";
log.error(msg);
throw new BadRequestException(msg);
}
}
}

@ -1,273 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.impl;
import io.entgra.device.mgt.core.application.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.application.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.application.mgt.common.Rating;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.ReviewManagementException;
import io.entgra.device.mgt.core.application.mgt.common.response.Review;
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.ReviewWrapper;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.store.api.services.ReviewManagementAPI;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
/**
* Review Management related jax-rs APIs.
*/
@Path("/reviews")
public class ReviewManagementAPIImpl implements ReviewManagementAPI {
private static final Log log = LogFactory.getLog(ReviewManagementAPIImpl.class);
@Override
@GET
@Path("/app/user/{uuid}")
public Response getUserReviews(
@PathParam("uuid") String uuid,
@DefaultValue("0") @QueryParam("offset") int offSet,
@DefaultValue("20") @QueryParam("limit") int limit) {
ReviewManager reviewManager = APIUtil.getReviewManager();
PaginationRequest request = new PaginationRequest(offSet, limit);
try {
PaginationResult paginationResult = reviewManager.getAllAppReviewsOfUser(request, uuid);
return Response.status(Response.Status.OK).entity(paginationResult).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application which has application release of UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException e) {
String msg = "Error occurred while retrieving reviews for application which has application release for "
+ "UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while retrieving application release details for application UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@GET
@Path("/app/{uuid}")
public Response getAllAppReviews(
@PathParam("uuid") String uuid,
@DefaultValue("0") @QueryParam("offset") int offSet,
@DefaultValue("20") @QueryParam("limit") int limit) {
ReviewManager reviewManager = APIUtil.getReviewManager();
PaginationRequest request = new PaginationRequest(offSet, limit);
try {
PaginationResult paginationResult = reviewManager.getAllAppReviews(request, uuid);
return Response.status(Response.Status.OK).entity(paginationResult).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application which has application release of UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException e) {
String msg = "Error occurred while retrieving reviews for application which has application release for "
+ "UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while retrieving application release details for application UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@POST
@Consumes("application/json")
@Path("/{uuid}")
public Response addReview(
@ApiParam ReviewWrapper reviewWrapper,
@PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
Review review = reviewManager.addReview(reviewWrapper, uuid, false);
if (review != null) {
return Response.status(Response.Status.CREATED).entity(reviewWrapper).build();
} else {
String msg = "Review adding is failed. Please contact the administrator.";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You have already reviewed the application. Hence you are not permitted to review the "
+ "application again.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ReviewManagementException e) {
String msg = "Error occurred while creating the reviewTmp";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while accessing application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@POST
@Consumes("application/json")
@Path("/{uuid}/{parentReviewId}")
public Response addReplyComment(
@ApiParam ReviewWrapper reviewWrapper,
@PathParam("uuid") String uuid,
@PathParam("parentReviewId") int parentReviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
boolean isRepliedForReview = reviewManager.addReplyComment(reviewWrapper, uuid, parentReviewId);
if (isRepliedForReview) {
return Response.status(Response.Status.CREATED).entity(reviewWrapper).build();
} else {
String msg = "Error occurred when adding reply comment for the review. Please contact the administrator..";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid payload data found with the requested add reply comment. Hence, please verify the "
+ "request payload.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}catch (ReviewManagementException e) {
String msg = "Error occurred while creating the reviewTmp";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while accessing application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Consumes("application/json")
@Path("/{uuid}/{reviewId}")
public Response updateReview(
@ApiParam ReviewWrapper updatingReview,
@PathParam("uuid") String uuid,
@PathParam("reviewId") int reviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
Review updatedReview = reviewManager.updateReview(updatingReview, reviewId, uuid, false);
if (updatedReview != null) {
return Response.status(Response.Status.OK).entity(updatedReview).build();
} else {
String msg = "Review updating failed. Please contact the administrator";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (ReviewManagementException e) {
String msg = "Error occurred while retrieving comments.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (NotFoundException e) {
String msg = "Couldn't found application release data for UUID " + uuid + " or Review for review ID: " + reviewId;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid payload data found with the request. Hence, please verify the request payload.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have permission to update application release review.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred when getting application release data for application release UUID:." + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); }
}
@Override
@DELETE
@Path("/{uuid}/{reviewId}")
public Response deleteReview(
@PathParam("uuid") String uuid,
@PathParam("reviewId") int reviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
reviewManager.deleteReview(uuid, reviewId, false);
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
} catch (NotFoundException e) {
String msg = "Couldn't found an application review to delete which match with the request.";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You are not permitted to delete the review.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ReviewManagementException e) {
String msg = "Error occurred while deleting the comment.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application release data.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@GET
@Path("/{uuid}/app-rating")
public Response getAppRating(
@PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager();
Rating rating;
try {
rating = reviewManager.getAppRating(uuid);
} catch (NotFoundException e) {
String msg = "Couldn't found an application for application release UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException | ApplicationManagementException e) {
String msg = "Error occurred while getting review data for application release UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
return Response.status(Response.Status.OK).entity(rating).build();
}
}

@ -1,498 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.impl;
import io.entgra.device.mgt.core.application.mgt.common.*;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationOperationTaskException;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.task.ScheduledAppSubscriptionTaskManager;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.store.api.services.SubscriptionManagementAPI;
import io.entgra.device.mgt.core.application.mgt.store.api.services.impl.util.RequestValidationUtil;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Properties;
/**
* Implementation of Subscription Management related APIs.
*/
@Produces({"application/json"})
@Path("/subscription")
public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
private static final Log log = LogFactory.getLog(SubscriptionManagementAPIImpl.class);
@Override
@POST
@Path("/{uuid}/devices/{action}")
public Response performAppOperationForDevices(
@PathParam("uuid") String uuid,
@PathParam("action") String action,
@Valid List<DeviceIdentifier> deviceIdentifiers,
@QueryParam("timestamp") long timestamp,
@QueryParam("block-uninstall") Boolean isUninstallBlocked
) {
Properties properties = new Properties();
if(isUninstallBlocked != null) {
properties.put(MDMAppConstants.AndroidConstants.IS_BLOCK_UNINSTALL, isUninstallBlocked);
}
try {
if (0 == timestamp) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
ApplicationInstallResponse response = subscriptionManager
.performBulkAppOperation(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(), action, properties);
return Response.status(Response.Status.OK).entity(response).build();
} else {
return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE,
SubAction.valueOf(action.toUpperCase()), timestamp, properties);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to perform "
+ "the action on the application.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg =
"Error occurred while installing the application release which has UUID: " + uuid + " for devices";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@POST
@Path("/{uuid}/{subType}/{action}")
public Response performBulkAppOperation(
@PathParam("uuid") String uuid,
@PathParam("subType") String subType,
@PathParam("action") String action,
@Valid List<String> subscribers,
@QueryParam("timestamp") long timestamp,
@QueryParam("block-uninstall") Boolean isUninstallBlocked,
@QueryParam("disable-operation-re-executing") boolean isOperationReExecutingDisabled
) {
Properties properties = new Properties();
if (isUninstallBlocked != null) {
properties.put(MDMAppConstants.AndroidConstants.IS_BLOCK_UNINSTALL, isUninstallBlocked);
}
try {
if (0 == timestamp) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
ApplicationInstallResponse response =
subscriptionManager.performBulkAppOperation(uuid, subscribers, subType, action, properties,
isOperationReExecutingDisabled);
return Response.status(Response.Status.OK).entity(response).build();
} else {
return scheduleApplicationOperationTask(uuid, subscribers,
SubscriptionType.valueOf(subType.toUpperCase()), SubAction.valueOf(action.toUpperCase()),
timestamp, properties, isOperationReExecutingDisabled);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to perform "
+ "the action on the application.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while installing the application release which has UUID: " + uuid
+ " for user devices";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@POST
@Path("/{uuid}/devices/ent-app-install/{action}")
public Response performEntAppSubscriptionOnDevices(
@PathParam("uuid") String uuid,
@PathParam("action") String action,
@Valid List<DeviceIdentifier> deviceIdentifiers,
@QueryParam("timestamp") long timestamp,
@QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal) {
try {
if (0 == timestamp) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
subscriptionManager
.performEntAppSubscription(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(),
action, requiresUpdatingExternal);
String msg = "Application release which has UUID " + uuid + " is installed to given valid device "
+ "identifiers.";
return Response.status(Response.Status.OK).entity(msg).build();
} else {
return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE,
SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + " to perform ent app installation "
+ "on subscriber's devices";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to install "
+ "the application.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg =
"Error occurred while performing ent app installation on the application release which has UUID: "
+ uuid + " for devices";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@POST
@Path("/{uuid}/{subType}/ent-app-install/{action}")
public Response performBulkEntAppSubscription(
@PathParam("uuid") String uuid,
@PathParam("subType") String subType,
@PathParam("action") String action,
@Valid List<String> subscribers,
@QueryParam("timestamp") long timestamp,
@QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal) {
try {
if (0 == timestamp) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
subscriptionManager.performEntAppSubscription(uuid, subscribers, subType, action, requiresUpdatingExternal);
String msg = "Application release which has UUID " + uuid + " is installed to subscriber's valid device"
+ " identifiers.";
return Response.status(Response.Status.OK).entity(msg).build();
} else {
return scheduleApplicationOperationTask(uuid, subscribers,
SubscriptionType.valueOf(subType.toUpperCase()),
SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to install "
+ "the application.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while performing ent app installation on the application release which has "
+ "UUID: " + uuid + " for user devices";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
/**
* Schedule the application subscription for the given timestamp
*
* @param applicationUUID UUID of the application to install
* @param subscribers list of subscribers. This list can be of
* either {@link io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier} if {@param subType} is
* equal to DEVICE or {@link String} if {@param subType} is USER, ROLE or GROUP
* @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code>
* {@see {@link io.entgra.device.mgt.core.application.mgt.common.SubscriptionType}}
* @param subAction action subscription action. E.g. <code>INSTALL/UNINSTALL</code>
* {@see {@link io.entgra.device.mgt.core.application.mgt.common.SubAction}}
* @param payload Properties sending to the device via operation
* @param timestamp timestamp to schedule the application subscription
* @return {@link Response} of the operation
*/
private Response scheduleApplicationOperationTask(String applicationUUID, List<?> subscribers,
SubscriptionType subType, SubAction subAction, long timestamp,
Properties payload) {
return scheduleApplicationOperationTask(applicationUUID, subscribers, subType, subAction, timestamp, payload,
false);
}
/**
* Schedule the application subscription for the given timestamp
*
* @param applicationUUID UUID of the application to install
* @param subscribers list of subscribers. This list can be of
* either {@link io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier} if {@param subType} is
* equal to DEVICE or {@link String} if {@param subType} is USER, ROLE or GROUP
* @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code>
* {@see {@link io.entgra.device.mgt.core.application.mgt.common.SubscriptionType}}
* @param subAction action subscription action. E.g. <code>INSTALL/UNINSTALL</code>
* {@see {@link io.entgra.device.mgt.core.application.mgt.common.SubAction}}
* @param timestamp timestamp to schedule the application subscription
* @param payload Properties sending to the device via operation
* @param isOperationReExecutingDisabled To prevent adding the application subscribing operation to devices that are
* already subscribed application successfully.
* @return {@link Response} of the operation
*/
private Response scheduleApplicationOperationTask(String applicationUUID, List<?> subscribers,
SubscriptionType subType, SubAction subAction, long timestamp,
Properties payload, boolean isOperationReExecutingDisabled) {
try {
ScheduledAppSubscriptionTaskManager subscriptionTaskManager = new ScheduledAppSubscriptionTaskManager();
subscriptionTaskManager.scheduleAppSubscriptionTask(applicationUUID, subscribers, subType, subAction,
timestamp, payload, isOperationReExecutingDisabled);
} catch (ApplicationOperationTaskException e) {
String msg = "Error occurred while scheduling the application install operation";
log.error(msg, e);
ErrorResponse errorResponse = new ErrorResponse(msg);
errorResponse.setDescription(e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).build();
}
return Response.status(Response.Status.CREATED).build();
}
@GET
@Consumes("application/json")
@Produces("application/json")
@Path("/{uuid}/devices")
public Response getAppInstalledDevices(
@QueryParam("name") String name,
@QueryParam("user") String user,
@QueryParam("ownership") String ownership,
@QueryParam("serialNumber") String serialNumber,
@PathParam("uuid") String uuid,
@DefaultValue("0")
@QueryParam("offset") int offset,
@DefaultValue("5")
@QueryParam("limit") int limit,
@QueryParam("status") List<String> status) {
try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationRequest request = new PaginationRequest(offset, limit);
if (name != null && !name.isEmpty()) {
request.setDeviceName(name);
}
if (user != null && !user.isEmpty()) {
request.setOwner(user);
}
if (ownership != null && !ownership.isEmpty()) {
RequestValidationUtil.validateOwnershipType(ownership);
request.setOwnership(ownership);
}
if (StringUtils.isNotBlank(serialNumber)) {
request.setSerialNumber(serialNumber);
}
if (status != null && !status.isEmpty()) {
boolean isStatusEmpty = true;
for (String statusString : status) {
if (StringUtils.isNotBlank(statusString)) {
isStatusEmpty = false;
break;
}
}
if (!isStatusEmpty) {
RequestValidationUtil.validateStatus(status);
request.setStatusList(status);
}
}
PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid);
DeviceList devices = new DeviceList();
devices.setList((List<Device>) subscribedDeviceDetails.getData());
devices.setCount(subscribedDeviceDetails.getRecordsTotal());
return Response.status(Response.Status.OK).entity(devices).build();
} catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "User requested details are not valid. Please verify the payload of the request.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state."
+ "Hence you are not permitted to get the devices details.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application with the application release uuid: "
+ uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Consumes("application/json")
@Produces("application/json")
@Path("/{uuid}/{subType}")
public Response getAppInstalledCategories(
@PathParam("uuid") String uuid,
@PathParam("subType") String subType,
@DefaultValue("0")
@QueryParam("offset") int offset,
@DefaultValue("5")
@QueryParam("limit") int limit) {
try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscribedCategoryDetails = subscriptionManager
.getAppInstalledSubscribers(offset, limit, uuid, subType);
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
BasicUserInfoList users = new BasicUserInfoList();
users.setList((List<BasicUserInfo>) subscribedCategoryDetails.getData());
users.setCount(subscribedCategoryDetails.getRecordsTotal());
return Response.status(Response.Status.OK).entity(users).build();
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
RoleList roles = new RoleList();
roles.setList(subscribedCategoryDetails.getData());
roles.setCount(subscribedCategoryDetails.getRecordsTotal());
return Response.status(Response.Status.OK).entity(roles).build();
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
DeviceGroupList groups = new DeviceGroupList();
groups.setList(subscribedCategoryDetails.getData());
groups.setCount(subscribedCategoryDetails.getRecordsTotal());
return Response.status(Response.Status.OK).entity(groups).build();
} else {
String msg = "Found invalid sub type ";
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
} catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid payload found when getting application. Hence verify the payload";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state."
+ "Hence you are not permitted to get the devices details.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application with the application " +
"release uuid: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Consumes("application/json")
@Produces("application/json")
@Path("/{uuid}/{subType}/{subTypeName}/devices")
public Response getAppInstalledDevicesOnCategories(
@PathParam("uuid") String uuid,
@PathParam("subType") String subType,
@PathParam("subTypeName") String subTypeName,
@DefaultValue("0")
@QueryParam("offset") int offset,
@DefaultValue("5")
@QueryParam("limit") int limit,
@QueryParam("name") String name,
@QueryParam("user") String user,
@QueryParam("ownership") String ownership,
@QueryParam("status") List<String> status) {
try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationRequest request = new PaginationRequest(offset, limit);
if (StringUtils.isNotBlank(name)) {
request.setDeviceName(name);
}
if (StringUtils.isNotBlank(user)) {
request.setOwner(user);
}
if (StringUtils.isNotBlank(ownership)) {
RequestValidationUtil.validateOwnershipType(ownership);
request.setOwnership(ownership);
}
if (status != null && !status.isEmpty()) {
boolean isStatusEmpty = true;
for (String statusString : status) {
if (StringUtils.isNotBlank(statusString)) {
isStatusEmpty = false;
break;
}
}
if (!isStatusEmpty) {
RequestValidationUtil.validateStatus(status);
request.setStatusList(status);
}
}
//todo need to update the API for other subscription types
if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
PaginationResult subscribedCategoryDetails = subscriptionManager
.getAppInstalledSubscribeDevices(request, uuid, subType, subTypeName);
DeviceList devices = new DeviceList();
devices.setList((List<Device>) subscribedCategoryDetails.getData());
devices.setCount(subscribedCategoryDetails.getRecordsTotal());
return Response.status(Response.Status.OK).entity(devices).build();
} else {
String msg = "Found invalid sub type: " + subType;
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
} catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid payload found with the request. Please verify the payload.";
log.error(msg,e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application with the application " +
"release uuid: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,68 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.impl.admin;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.ReviewManagementException;
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.store.api.services.admin.ReviewManagementStoreAdminAPI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* Review Management related jax-rs APIs.
*/
@Path("/admin/reviews")
public class ReviewManagementStoreAdminAPIImpl implements ReviewManagementStoreAdminAPI {
private static final Log log = LogFactory.getLog(ReviewManagementStoreAdminAPIImpl.class);
@Override
@DELETE
@Path("/{uuid}/{reviewId}")
@Produces(MediaType.WILDCARD)
@Consumes(MediaType.WILDCARD)
public Response deleteReview(
@PathParam("uuid") String uuid,
@PathParam("reviewId") int reviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
reviewManager.deleteReview(uuid, reviewId, true);
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
} catch (NotFoundException e) {
String msg = "Couldn't found an application review to delete which match with the request.";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException e) {
String msg = "Error occurred while deleting the comment.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application release data.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,139 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.impl.admin;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.store.api.beans.SubscriptionStatusBean;
import io.entgra.device.mgt.core.application.mgt.store.api.services.admin.SubscriptionManagementAdminAPI;
import io.entgra.device.mgt.core.application.mgt.store.api.services.impl.util.RequestValidationUtil;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* Implementation of Subscription Management related APIs.
*/
@Produces({"application/json"})
@Path("/admin/subscription")
public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagementAdminAPI {
private static final Log log = LogFactory.getLog(SubscriptionManagementAdminAPIImpl.class);
@Override
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/device/{deviceId}/status")
public Response updateSubscription(
@PathParam("deviceId") int deviceId,
SubscriptionStatusBean subscriptionStatusBean
) {
try {
RequestValidationUtil.validateSubscriptionStatus(subscriptionStatusBean.getStatus());
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
subscriptionManager.updateSubscriptionStatus(deviceId, subscriptionStatusBean.getSubId(),
subscriptionStatusBean.getStatus());
return Response.status(Response.Status.OK).entity("Subscription status updated successfully").build();
} catch (BadRequestException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (SubscriptionManagementException e) {
String msg = "Error occurred while changing subscription status of the subscription with the id "
+ subscriptionStatusBean.getSubId();
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Consumes("application/json")
@Produces("application/json")
@Path("/{uuid}")
public Response getAppInstalledDevices(
@QueryParam("name") String name,
@QueryParam("user") String user,
@QueryParam("action") String action,
@QueryParam("actionStatus") String actionStatus,
@QueryParam("status") List<String> status,
@QueryParam("installedVersion") String installedVersion,
@PathParam("uuid") String uuid,
@DefaultValue("0")
@QueryParam("offset") int offset,
@DefaultValue("5")
@QueryParam("limit") int limit) {
try {
PaginationRequest request = new PaginationRequest(offset, limit);
if (name != null && !name.isEmpty()) {
request.setDeviceName(name);
}
if (user != null && !user.isEmpty()) {
request.setOwner(user);
}
if (action != null && !action.isEmpty()) {
RequestValidationUtil.validateAction(action);
}
if (status != null && !status.isEmpty()) {
boolean isStatusEmpty = true;
for (String statusString : status) {
if (StringUtils.isNotBlank(statusString)) {
isStatusEmpty = false;
break;
}
}
if (!isStatusEmpty) {
RequestValidationUtil.validateStatus(status);
request.setStatusList(status);
}
}
if (actionStatus != null && !actionStatus.isEmpty()) {
if (StringUtils.isNotBlank(actionStatus)) {
RequestValidationUtil.validateStatusFiltering(actionStatus);
}
}
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails
(request, uuid, actionStatus, action, installedVersion);
return Response.status(Response.Status.OK).entity(subscriptionData).build();
} catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "User requested details are not valid. Please verify the request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting app installed devices which has application release UUID of: "
+ uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,143 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services.impl.util;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.store.api.util.Constants;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.ActivityStatus;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.List;
public class RequestValidationUtil {
private static final Log log = LogFactory.getLog(RequestValidationUtil.class);
/**
* Checks if user requested status codes are valid.
*
* @param statusList status codes upon to filter operation logs using status
*/
public static void validateStatus(List<String> statusList) throws BadRequestException {
for (String status : statusList) {
switch (status) {
case "ACTIVE":
case "INACTIVE":
case "UNCLAIMED":
case "UNREACHABLE":
case "SUSPENDED":
case "DISENROLLMENT_REQUESTED":
case "REMOVED":
case "BLOCKED":
case "CREATED":
case "CONFIGURED":
case "READY_TO_CONNECT":
case "RETURN_PENDING":
case "RETURNED":
case "DEFECTIVE":
case "WARRANTY_PENDING":
case "WARRANTY_SENT":
case "WARRANTY_REPLACED":
case "ASSIGNED":
break;
default:
String msg = "Invalid enrollment status type: " + status + ". \nValid status types " +
"are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
"DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED | CONFIGURED | READY_TO_CONNECT | " +
"RETURN_PENDING | RETURNED | DEFECTIVE | WARRANTY_PENDING | WARRANTY_SENT | " +
"WARRANTY_REPLACED | ASSIGNED |";
log.error(msg);
throw new BadRequestException(msg);
}
}
}
/**
* Checks if user requested action is valid.
*
* @param action action upon to filter devices using action
*/
public static void validateAction(String action) throws BadRequestException {
if (action.equals("SUBSCRIBED") || action.equals("UNSUBSCRIBED")) {
} else {
String msg = "Invalid action type received.Valid action types are SUBSCRIBED | UNSUBSCRIBED";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Checks if user requested ownerships are valid.
*
* @param ownership ownerships upon to filter devices using ownership
*/
public static void validateOwnershipType(String ownership) throws BadRequestException {
switch (ownership) {
case "BYOD":
case "COPE":
case "WORK_PROFILE":
case "GOOGLE_ENTERPRISE":
case "COSU":
case "FULLY_MANAGED":
case "DEDICATED_DEVICE":
break;
default:
String msg = "Invalid ownership type received.Valid ownership types are BYOD | COPE | WORK_PROFILE |" +
"GOOGLE_ENTERPRISE | COSU | FULLY_MANAGED | DEDICATED_DEVICE";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Checks if user requested Action status codes are valid.
*
* @param status status codes upon to filter operation logs using status
*/
public static void validateStatusFiltering(String status) throws BadRequestException {
if (Constants.OperationStatus.COMPLETED.toUpperCase().equals(status)
|| Constants.OperationStatus.ERROR.toUpperCase().equals(status)
|| Constants.OperationStatus.NOTNOW.toUpperCase().equals(status)
|| Constants.OperationStatus.REPEATED.toUpperCase().equals(status)
|| Constants.OperationStatus.PENDING.toUpperCase().equals(status)
|| Constants.OperationStatus.IN_PROGRESS.toUpperCase().equals(status)) {
} else {
String msg = "Invalid status type: " + status + ". \nValid status types are COMPLETED | ERROR | " +
"IN_PROGRESS | NOTNOW | PENDING | REPEATED";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Checks if user requested subscription status is valid.
*
*/
public static void validateSubscriptionStatus(String status) throws BadRequestException{
if (!EnumUtils.isValidEnum(ActivityStatus.Status.class, status)) {
List<ActivityStatus.Status> validStatuses = EnumUtils.getEnumList(ActivityStatus.Status.class);
String validStatusesString = StringUtils.join(validStatuses, " | ");
String msg = "Invalid status type: " + status + ". \nValid status types are " + validStatusesString;
log.error(msg);
throw new BadRequestException(msg);
}
}
}

@ -1,84 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.util;
/**
* Holds the constants used by DeviceImpl Management Admin web application.
*/
public class Constants {
public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress";
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
public static final String USER_CLAIM_CREATED = "http://wso2.org/claims/created";
public static final String USER_CLAIM_MODIFIED = "http://wso2.org/claims/modified";
public static final String USER_CLAIM_DEVICES = "http://wso2.org/claims/devices";
public static final String PRIMARY_USER_STORE = "PRIMARY";
public static final String DEFAULT_STREAM_VERSION = "1.0.0";
public static final String SCOPE = "scope";
public static final String JDBC_USERSTOREMANAGER = "org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager";
public static final String DEFAULT_SIMPLE_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
public static final int DEFAULT_PAGE_LIMIT = 50;
public static final String FORWARD_SLASH = "/";
public static final String ANDROID = "android";
public static final String ANDROID_POLICY_VALIDATOR = "io.entgra.proprietary.uem.platform.android." +
"core.polcy.AndroidPolicyPayloadValidator";
public static final String IOS = "ios";
public static final String WINDOWS = "windows";
public final class OperationStatus {
private OperationStatus () { throw new AssertionError(); }
public static final String COMPLETED = "completed";
public static final String ERROR = "error";
public static final String IN_PROGRESS = "in_progress";
public static final String PENDING = "pending";
public static final String NOTNOW = "notnow";
public static final String REPEATED = "repeated";
}
public static final String DEVICES = "devices";
public static final String ATTRIBUTE_DISPLAY_NAME = "DisplayName";
public static final String ATTRIBUTE_DESCRIPTION = "Description";
public static final String EXTERNAL_DEVICE_CLAIM_DISPLAY_NAME = "Devices";
public static final String EXTERNAL_DEVICE_CLAIM_DESCRIPTION = "Device list";
public final class ErrorMessages {
private ErrorMessages () { throw new AssertionError(); }
public static final String STATUS_BAD_REQUEST_MESSAGE_DEFAULT = "Bad Request";
}
public final class DeviceConstants {
private DeviceConstants () { throw new AssertionError(); }
public static final String APPLICATION_JSON = "application/json";
public static final String HEADER_CONTENT_TYPE = "Content-Type";
}
public final class Permission {
private Permission() { throw new AssertionError(); }
public static final String ADMIN = "/permission/admin";
public static final String LOGIN = "/permission/admin/login";
public static final String DEVICE_MGT = "/permission/admin/device-mgt";
public static final String APP_MGT = "/permission/admin/app-mgt";
}
}

@ -1,110 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<!-- 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>
<!-- ApplicationDTO related permissions -->
<Permission>
<name>Get Application</name>
<path>/device-mgt/application/get</path>
<url>/application-mgt/applications</url>
<method>GET</method>
</Permission>
<Permission>
<name>Create Application</name>
<path>/device-mgt/application/create</path>
<url>/application-mgt/applications</url>
<method>POST</method>
</Permission>
<Permission>
<name>Edit Application</name>
<path>/device-mgt/application/update</path>
<url>/application-mgt/applications</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Login to Application Management</name>
<path>/device-mgt/application-mgt/login</path>
<url>/application-mgt/applications</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Login to Application Management</name>
<path>device-mgt/application/delete</path>
<url>/application-mgt/applications/*</url>
<method>DELETE</method>
</Permission>
<!-- Platform related permissions -->
<Permission>
<name>Get Platform</name>
<path>/device-mgt/platform/get</path>
<url>/application-mgt/platforms/*</url>
<method>GET</method>
</Permission>
<Permission>
<name>Add Platform</name>
<path>/device-mgt/platform/add</path>
<url>/application-mgt/platforms</url>
<method>POST</method>
</Permission>
<Permission>
<name>Update Platform</name>
<path>/device-mgt/platform/update</path>
<url>/application-mgt/platforms/*</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Remove Platform</name>
<path>/device-mgt/platform/remove</path>
<url>/application-mgt/platforms/*</url>
<method>DELETE</method>
</Permission>
<!-- Subscription related permissions -->
<Permission>
<name>Install Application</name>
<path>/device-mgt/subscription/install</path>
<url>/application-mgt/subscription</url>
<method>POST</method>
</Permission>
<Permission>
<name>Uninstall Application</name>
<path>/device-mgt/subscription/uninstall</path>
<url>/application-mgt/subscription</url>
<method>POST</method>
</Permission>
<Permission>
<name>Get Application</name>
<path>/device-mgt/subscription/getApplication</path>
<url>/application-mgt/subscription</url>
<method>GET</method>
</Permission>
</PermissionConfiguration>

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<!--
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>CXF3,Carbon</Environments>
</Classloading>

@ -1,72 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
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 http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<jaxrs:server id="applicationMgtService" address="/">
<jaxrs:serviceBeans>
<ref bean="subscriptionMgtAdminServiceBean"/>
<ref bean="reviewMgtAdminServiceBean"/>
<ref bean="applicationMgtServiceBean"/>
<ref bean="reviewMgtServiceBean"/>
<ref bean="subscriptionMgtServiceBean"/>
<ref bean="swaggerResource"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="multipartProvider"/>
<ref bean="swaggerWriter"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="io.entgra.device.mgt.core.application.mgt.store.api"/>
<property name="version" value="1.0"/>
<property name="host" value="localhost:9443"/>
<property name="schemes" value="https" />
<property name="basePath" value="/api/application-mgt-store/v1.0"/>
<property name="title" value="App Store Management Service API Definitions"/>
<property name="contact" value="bizdev-group@entgra.io"/>
<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="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor" class="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor"/>
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="reviewMgtAdminServiceBean" class="io.entgra.device.mgt.core.application.mgt.store.api.services.impl.admin.ReviewManagementStoreAdminAPIImpl" />
<bean id="subscriptionMgtAdminServiceBean" class="io.entgra.device.mgt.core.application.mgt.store.api.services.impl.admin.SubscriptionManagementAdminAPIImpl" />
<bean id="applicationMgtServiceBean" class="io.entgra.device.mgt.core.application.mgt.store.api.services.impl.ApplicationManagementAPIImpl"/>
<bean id="reviewMgtServiceBean" class="io.entgra.device.mgt.core.application.mgt.store.api.services.impl.ReviewManagementAPIImpl" />
<bean id="subscriptionMgtServiceBean" class="io.entgra.device.mgt.core.application.mgt.store.api.services.impl.SubscriptionManagementAPIImpl"/>
<bean id="jsonProvider" class="io.entgra.device.mgt.core.application.mgt.addons.JSONMessageHandler"/>
<bean id="multipartProvider" class="io.entgra.device.mgt.core.application.mgt.addons.MultipartCustomProvider"/>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="io.entgra.device.mgt.core.application.mgt.addons.ValidationInterceptor"/>
</cxf:inInterceptors>
</cxf:bus>
</beans>

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>App Store Management Webapp</display-name>
<servlet>
<description>JAX-WS/JAX-RS App Store 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>
<!-- configure a security filter -->
<init-param>
<param-name>swagger.security.filter</param-name>
<param-value>ApiAuthorizationFilterImpl</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</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>doAuthentication</param-name>
<param-value>true</param-value>
</context-param>
<!-- Below configuration is used to redirect http requests to https -->
<security-constraint>
<web-resource-collection>
<web-resource-name>ApplicationMgt-Admin</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!--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>
<context-param>
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>io.entgra.device.mgt.core.application.mgt.addons.ApiOriginFilter</filter-class>
</filter>
<filter>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class>
<init-param>
<param-name>patterns</param-name>
<param-value>text/html" ,application/json" ,text/plain</param-value>
</init-param>
<init-param>
<param-name>filterAction</param-name>
<param-value>enforce</param-value>
</init-param>
<init-param>
<param-name>httpHeaders</param-name>
<param-value>Cache-Control: no-store, no-cache, must-revalidate, private</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -1,51 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services;
import io.entgra.device.mgt.core.application.mgt.common.response.Review;
/**
* Helper class for Review Management API test cases.
*/
public class CommentMgtTestHelper {
private static final String COMMENT_TEXT = "Dummy Review";
private static final String CREATED_BY = "TEST_CREATED_BY";
private static final String MODIFIED_BY = "TEST_MODIFIED_BY";
private static final int PARENT_ID = 123;
private static final int COMMENT_ID = 1;
/**
* Creates a Review with given text and given uuid.
* If the text is null, the COMMENT_TEXT will be used as the Dummy Review.
*
* @param commentText : Text of the Review
* @return Review
*/
public static Review getDummyComment(String commentText, String uuid) {
Review reviewTmp = new Review();
reviewTmp.setId(COMMENT_ID);
reviewTmp.setUsername(CREATED_BY);
reviewTmp.setContent(commentText != null ? commentText : COMMENT_TEXT);
return reviewTmp;
}
}

@ -1,224 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.store.api.services;
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
@PowerMockIgnore("javax.ws.rs.*")
@SuppressStaticInitializationFor({
"io.entgra.device.mgt.core.application.mgt.api.APIUtil" })
@PrepareForTest({ APIUtil.class, ReviewManager.class,
ReviewManagementAPITest.class})
@Ignore("Since comment manager logic is invalid temporarily added Ignore annotation to skip running comment management test cases") public class ReviewManagementAPITest
extends
TestCase {
private static final Log log = LogFactory.getLog(ReviewManagementAPI.class);
private ReviewManagementAPI commentManagementAPI;
private ReviewManager reviewManager;
//
// @ObjectFactory
// public IObjectFactory getObjectFactory() {
// return new org.powermock.modules.testng.PowerMockObjectFactory();
// }
//
// @BeforeClass
// void init() throws ReviewManagementException {
//
// log.info("Initializing ReviewManagementAPI tests");
// initMocks(this);
// this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS);
// this.commentManagementAPI = new ReviewManagementAPIImpl();
// }
//
// @Test
// public void testGetAllCommentsWithValidDetails() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.getAllReleaseReviews("a", 1, 2);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
// "The response status should be 200.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testGetAllCommentsInternalError() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager)
// .getAllReleaseReviews(Mockito.any(), Mockito.anyString());
// Response response = this.commentManagementAPI.getAllReleaseReviews("a", 1, 4);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
// "The response status should be 500.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testGetAllCommentsNotFoundError() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.getAllReleaseReviews(null, 1, 3);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
// "The response status should be 404.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testAddComments() throws Exception {
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.addReview(review, "a");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
// "The response status should be 201.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testAddNullComment() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.addReview(null, "a");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
// "The response status should be 400.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testAddCommentsInternalError() throws Exception {
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString()))
// .thenThrow(new ReviewManagementException());
// Response response = this.commentManagementAPI.addReview(review, null);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
// "The response status should be 500.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testUpdateComment() throws Exception {
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.updateReview(review, 1);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
// "The response status should be 200.");
// }
//
// @Test
// public void testUpdateNullComment() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.updateReview(null, 1);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
// "The response status should be 400.");
// }
//
// @Test
// public void testUpdateCommentWhenNullCommentId() throws Exception {
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.updateReview(review, 0);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
// "The response status should be 404.");
// }
//
// @Test
// public void testUpdateCommentInternalServerError() throws Exception {
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
// Response response = this.commentManagementAPI.updateReview(review, 9);
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
// "The response status should be 500.");
// }
//
// @Test
// public void testDeleteComment() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.deleteReview(1,"");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
// "The response status should be 200.");
// }
//
// @Test
// public void testDeleteCommentInternalError() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Mockito.when(this.commentManagementAPI.deleteReview(1,"")).thenThrow(new ReviewManagementException());
// Response response = this.commentManagementAPI.deleteReview(1,"");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
// "The response status should be 500.");
// }
//
// @Test
// public void testDeleteCommentNotFoundError() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.deleteReview(0,"");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
// "The response status should be 404.");
// }
//
// @Test
// public void testGetStars() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Response response = this.commentManagementAPI.getAppReleaseRating("a");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
// "The response status should be 200.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testGetStarsCommentError() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Mockito.when(this.commentManagementAPI.getAppReleaseRating(Mockito.anyString()))
// .thenThrow(new ReviewManagementException());
// Response response = this.commentManagementAPI.getAppReleaseRating("a");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
// "The response status should be 500.");
// Mockito.reset(reviewManager);
// }
//
// @Test
// public void testGetStarsApplicationError() throws Exception {
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
// Mockito.when(this.commentManagementAPI.getAppReleaseRating(Mockito.anyString()))
// .thenThrow(new ApplicationManagementException());
// Response response = this.commentManagementAPI.getAppReleaseRating("a");
// Assert.assertNotNull(response, "The response object is null.");
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
// "The response status should be 500.");
// Mockito.reset(reviewManager);
// }
}

@ -1,23 +0,0 @@
#
# Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
#
# Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
log4j.rootLogger=DEBUG, STD_OUT
# Redirect log messages to console
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
log4j.appender.STD_OUT.Target=System.out
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

@ -1,29 +0,0 @@
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="CommentManagementAPI">
<parameter name="useDefaultListeners" value="false"/>
<test name="API Unit Tests" preserve-order="true">
<classes>
<class name="io.entgra.device.mgt.core.application.mgt.store.api.services.ReviewManagementAPITest"/>
</classes>
</test>
</suite>

@ -36,10 +36,6 @@
<modules>
<module>io.entgra.device.mgt.core.application.mgt.common</module>
<module>io.entgra.device.mgt.core.application.mgt.core</module>
<module>io.entgra.device.mgt.core.application.mgt.addons</module>
<module>io.entgra.device.mgt.core.application.mgt.publisher.api</module>
<module>io.entgra.device.mgt.core.application.mgt.store.api</module>
<module>io.entgra.device.mgt.core.application.mgt.api</module>
</modules>
<build>

@ -512,13 +512,6 @@
<dependency>
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1.wso2v1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1.wso2v1</version>
<scope>compile</scope>
</dependency>
</dependencies>

@ -1313,7 +1313,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
}
//Add the query for owner
if (owner != null && !owner.isEmpty()) {
sql = sql + " AND e.OWNER = ?";
sql = sql + " AND e.OWNER LIKE ?";
isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
@ -1341,7 +1341,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
stmt.setString(paramIdx++, request.getOwnership());
}
if (isOwnerProvided) {
stmt.setString(paramIdx++, owner);
stmt.setString(paramIdx++, "%" + owner + "%");
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
}

@ -118,7 +118,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
//Add the query for owner
if (owner != null && !owner.isEmpty()) {
sql = sql + " AND e.OWNER = ?";
sql = sql + " AND e.OWNER LIKE ?";
isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
@ -150,7 +150,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
stmt.setString(paramIdx++, ownership);
}
if (isOwnerProvided) {
stmt.setString(paramIdx++, owner);
stmt.setString(paramIdx++, "%" + owner + "%");
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
}

@ -78,6 +78,8 @@ public interface DeviceInformationManager {
void addDeviceLocation(Device device, DeviceLocation deviceLocation) throws DeviceDetailsMgtException;
void deleteDeviceLocation(Device device) throws DeviceDetailsMgtException;
void addDeviceLocations(Device device, List<DeviceLocation> deviceLocations) throws
DeviceDetailsMgtException;

@ -48,7 +48,11 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.user.api.UserStoreException;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DeviceInformationManagerImpl implements DeviceInformationManager {
@ -412,6 +416,35 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
}
}
@Override
public void deleteDeviceLocation(Device device) throws DeviceDetailsMgtException {
try {
if (log.isDebugEnabled()) {
log.debug("Deleting device location for device: " + device.getId());
}
DeviceManagementDAOFactory.beginTransaction();
DeviceLocation deviceLocation = deviceDetailsDAO.getDeviceLocation(device.getId(),
device.getEnrolmentInfo().getId());
if (deviceLocation != null) {
deviceDetailsDAO.deleteDeviceLocation(device.getId(), device.getEnrolmentInfo().getId());
} else {
log.error("Device location not found for device: " + device.getId());
throw new DeviceDetailsMgtException("Device location not found for device: " + device.getId());
}
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
log.error("Transactional error occurred while deleting the device location information. Device ID: " + device.getId(), e);
throw new DeviceDetailsMgtException("Transactional error occurred while deleting the device location " +
"information.", e);
} catch (DeviceDetailsMgtDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
log.error("Error occurred while deleting the device location information. Device ID: " + device.getId(), e);
throw new DeviceDetailsMgtException("Error occurred while deleting the device location information.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Override
public void addDeviceLocations(Device device, List<DeviceLocation> deviceLocations) throws DeviceDetailsMgtException {
try {

@ -1,167 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt-feature</artifactId>
<version>5.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.application.mgt.api.feature</artifactId>
<packaging>pom</packaging>
<name>Entgra - Application Management API Feature</name>
<url>https://entgra.io</url>
<description>This feature contains the APIs required for Application Management console UI</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>publisher-copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.publisher.api
</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>
${project.build.directory}/maven-shared-archive-resources/webapps
</outputDirectory>
<destFileName>api#application-mgt-publisher#v1.0.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>store-copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.store.api
</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>
${project.build.directory}/maven-shared-archive-resources/webapps
</outputDirectory>
<destFileName>api#application-mgt-store#v1.0.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>app-mgt-copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.api
</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>
${project.build.directory}/maven-shared-archive-resources/webapps
</outputDirectory>
<destFileName>api#application-mgt#v1.0.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources</outputDirectory>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>build.properties</include>
<include>p2.inf</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
<executions>
<execution>
<id>p2-feature-generation</id>
<phase>package</phase>
<goals>
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>io.entgra.device.mgt.core.application.mgt.api</id>
<propertiesFile>../../../features/etc/feature.properties
</propertiesFile>
<adviceFile>
<properties>
<propertyDef>org.wso2.carbon.p2.category.type:server
</propertyDef>
<propertyDef>org.eclipse.equinox.p2.type.group:false
</propertyDef>
</properties>
</adviceFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -1,19 +0,0 @@
#
# Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
#
# Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
custom = true

@ -1,5 +0,0 @@
instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.application.mgt.api_${feature.version}/webapps/api#application-mgt-publisher#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#application-mgt-publisher#v1.0.war,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.application.mgt.api_${feature.version}/webapps/api#application-mgt-store#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#application-mgt-store#v1.0.war,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.application.mgt.api_${feature.version}/webapps/api#application-mgt#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#application-mgt#v1.0.war,overwrite:true);\

@ -33,7 +33,6 @@
<url>https://entgra.io</url>
<modules>
<module>io.entgra.device.mgt.core.application.mgt.api.feature</module>
<module>io.entgra.device.mgt.core.application.mgt.server.feature</module>
</modules>
</project>

@ -186,11 +186,6 @@
<artifactId>io.entgra.device.mgt.core.certificate.mgt.core</artifactId>
<version>${io.entgra.device.mgt.core.version}</version>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.addons</artifactId>
<version>${io.entgra.device.mgt.core.version}</version>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.core</artifactId>
@ -201,16 +196,6 @@
<artifactId>io.entgra.device.mgt.core.application.mgt.common</artifactId>
<version>${io.entgra.device.mgt.core.version}</version>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.publisher.api</artifactId>
<version>${io.entgra.device.mgt.core.version}</version>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.application.mgt.store.api</artifactId>
<version>${io.entgra.device.mgt.core.version}</version>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.policy.mgt.common</artifactId>

Loading…
Cancel
Save