Merge branch 'application-mgt-new' into 'application-mgt-new'

Refactor the source and merge with master

See merge request entgra/carbon-device-mgt!21
feature/appm-store/pbac
Inosh Perara 6 years ago
commit bd7da87e08

@ -1,7 +1,7 @@
image: maven:latest
variables:
MAVEN_CLI_OPTS: "--batch-mode"
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
@ -17,4 +17,11 @@ build:
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
- mvn $MAVEN_CLI_OPTS test
deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS deploy -Dmaven.test.skip=true
only:
- master

@ -0,0 +1,12 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>maven-snapshots</id>
<username>${env.MAVEN_REPO_USER}</username>
<password>${env.MAVEN_REPO_PASS}</password>
</server>
</servers>
</settings>

@ -1,7 +1,8 @@
# carbon-device-mgt
<a href='https://opensource.org/licenses/Apache-2.0'><img src='https://img.shields.io/badge/License-Apache%202.0-blue.svg'></a><br/>
<a href='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt/'><img src='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt/badge/icon'></a> - Java8<br/>
[![pipeline status](https://gitlab.com/entgra/carbon-device-mgt/badges/master/pipeline.svg)](https://gitlab.com/entgra/carbon-device-mgt/commits/master)
WSO2 CONNECTED DEVICE MANAGEMENT COMPONENTS

@ -22,13 +22,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Annotations</name>
<description>WSO2 Carbon - API Management Custom Annotation Module</description>

@ -21,12 +21,12 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<artifactId>org.wso2.carbon.apimgt.application.extension.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - API Application Management API</name>

@ -22,12 +22,12 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Application Management</name>

@ -21,13 +21,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.handlers</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Security Handler Component</name>
<description>WSO2 Carbon - API Management Security Handler Module</description>

@ -13,13 +13,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Integration Client</name>
<description>WSO2 Carbon - API Management Integration Client</description>

@ -13,13 +13,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Integration Generated Client</name>
<description>WSO2 Carbon - API Management Integration Client</description>

@ -22,13 +22,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Webapp Publisher</name>
<description>WSO2 Carbon - API Management Webapp Publisher</description>

@ -22,13 +22,13 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>carbon-devicemgt</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apimgt-extensions</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WSO2 Carbon - API Management Extensions Component</name>
<url>http://wso2.org</url>

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>org.wso2.carbon.devicemgt</groupId>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.addons</artifactId>
<version>3.2.1-SNAPSHOT</version>
<name>WSO2 Carbon - Application Management Add-Ons</name>
<description>WSO2 Carbon - Application Management Add-Ons</description>
<url>http://wso2.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
<Bundle-Description>Application Management Add-Ons Bundle</Bundle-Description>
<Import-Package>
com.google.gson,
io.swagger.annotations.*;resolution:=optional
</Import-Package>
<Export-Package>
org.wso2.carbon.device.application.mgt.addons.*
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<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>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
</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>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
</project>

@ -15,7 +15,8 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.store.api;
package org.wso2.carbon.device.application.mgt.addons;
import javax.servlet.Filter;
import javax.servlet.FilterChain;

@ -1,5 +1,4 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
@ -16,17 +15,17 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.addons;
package org.wso2.carbon.device.application.mgt.store.api;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.StreamingOutput;
/**
* FileStreamingOutput to allow the user to send the files as Stream.
* org.wso2.carbon.device.application.mgt.addons.FileStreamingOutput to allow the user to send the files as Stream.
*/
public class FileStreamingOutput implements StreamingOutput {
private InputStream inputStream;

@ -15,21 +15,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.store.api;
package org.wso2.carbon.device.application.mgt.addons;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.wso2.carbon.device.application.mgt.common.jaxrs.AnnotationExclusionStrategy;
import org.wso2.carbon.device.application.mgt.addons.jaxrs.AnnotationExclusionStrategy;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
@ -38,6 +29,13 @@ 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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

@ -1,4 +1,4 @@
/*
package org.wso2.carbon.device.application.mgt.addons;/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
@ -16,26 +16,24 @@
*
*/
package org.wso2.carbon.device.application.mgt.store.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.wso2.carbon.device.application.mgt.common.jaxrs.AnnotationExclusionStrategy;
import org.wso2.carbon.device.application.mgt.addons.jaxrs.AnnotationExclusionStrategy;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
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

@ -15,9 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.store.api;
package org.wso2.carbon.device.application.mgt.addons;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -119,6 +117,6 @@ public class ValidationInterceptor extends AbstractPhaseInterceptor<Message> {
}
}
public void handleFault(Message messageParam) {
public void handleFault(org.apache.cxf.message.Message messageParam) {
}
}

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.common.jaxrs;
package org.wso2.carbon.device.application.mgt.addons.jaxrs;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.common.jaxrs;
package org.wso2.carbon.device.application.mgt.addons.jaxrs;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

@ -24,11 +24,11 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>application-mgt</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<artifactId>org.wso2.carbon.device.application.mgt.authhandler</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>WSO2 Carbon - Application Management Authentication Handler API</name>
<description>Proxy Service for Authentication Handling in WSO2 App Manager.</description>

@ -21,13 +21,13 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>application-mgt</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.common</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Application Management Common</name>
<description>WSO2 Carbon - Application Management Common</description>
@ -53,7 +53,9 @@
<Import-Package>
org.wso2.carbon.device.mgt.common.*;version="${carbon.device.mgt.version}",
com.google.gson,
io.swagger.annotations.*;resolution:=optional
io.swagger.annotations.*;resolution:=optional,
com.fasterxml.jackson.annotation,
javax.validation.constraints
</Import-Package>
<Export-Package>
org.wso2.carbon.device.application.mgt.common.*
@ -106,6 +108,10 @@
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
</project>

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api.beans;
package org.wso2.carbon.device.application.mgt.common;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;

@ -16,11 +16,12 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api.beans;
package org.wso2.carbon.device.application.mgt.common;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.application.mgt.common.ErrorListItem;
import java.util.ArrayList;
import java.util.List;

@ -19,17 +19,11 @@
*/
package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
import java.util.Date;
/**
* Application represents the an Application in Application Store.
*/
public class Tag {
@Exclude
private int id;
private String tenantId;

@ -19,15 +19,11 @@
*/
package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
/**
* Application represents the an Application in Application Store.
*/
public class UnrestrictedRole {
@Exclude
private int id;
private int tenantId;

@ -18,16 +18,17 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
import javassist.NotFoundException;
import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
/**
* ReviewManager is responsible for handling all the add/update/delete/get operations related with
*/
@ -41,7 +42,8 @@ public interface ReviewManager {
* @return {@link Review} Review added
* @throws ReviewManagementException Exceptions of the review management.
*/
boolean addReview(Review review, String uuid) throws ReviewManagementException, RequestValidatingException;
boolean addReview(Review review, String uuid)
throws ReviewManagementException, RequestValidatingException, ApplicationManagementException;
/**
* Get all review with pagination

@ -21,13 +21,13 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>application-mgt</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.core</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Application Management Core</name>
<description>WSO2 Carbon - Application Management Core</description>

@ -139,4 +139,13 @@ public interface ApplicationReleaseDAO {
*/
boolean verifyReleaseExistence(int appId, String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To verify whether application release exist or not for given application release uuid.
*
* @param uuid UUID of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
boolean verifyReleaseExistenceByUuid(String uuid, int tenantId) throws ApplicationManagementDAOException;
}

@ -55,8 +55,8 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
}
PreparedStatement statement = null;
ResultSet rs = null;
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME,CREATED_AT, MODIFIES_AT,"
+ " AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, RATING, USERNAME,CREATED_AT, MODIFIED_AT, "
+ "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
+ "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));";
try {
Calendar calendar = Calendar.getInstance();
@ -67,11 +67,12 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(1, tenantId);
statement.setString(2, review.getComment());
statement.setInt(3, review.getParentId());
statement.setString(4, review.getUsername());
statement.setTimestamp(5,timestamp);
statement.setTimestamp(6,timestamp);
statement.setString(7,uuid);
statement.setInt(4, review.getRating());
statement.setString(5, review.getUsername());
statement.setTimestamp(6, timestamp);
statement.setTimestamp(7,timestamp);
statement.setString(8,uuid);
statement.setString(9,uuid);
statement.executeUpdate();
rs = statement.getGeneratedKeys();
return rs.next();
@ -99,7 +100,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
PreparedStatement statement = null;
ResultSet rs = null;
Review review = null;
sql = "SELECT ID, COMMENT, CREATED_AT, MODEFIED_AT, USERNAME, PARENT_ID, RATING FROM AP_APP_REVIEW WHERE "
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, USERNAME, PARENT_ID, RATING FROM AP_APP_REVIEW WHERE "
+ "AP_APP_RELEASE_ID = (SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) AND USERNAME = ? AND TENANT_ID = ?;";
try {
conn = this.getDBConnection();
@ -173,18 +174,18 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
Connection conn;
PreparedStatement statement = null;
ResultSet rs = null;
Review review = new Review();
Review review = null;
try {
conn = this.getDBConnection();
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEWE WHERE ID=?;";
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEW WHERE ID=?;";
statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId);
rs = statement.executeQuery();
if (rs.next()) {
review = new Review();
review.setId(rs.getInt("ID"));
review.setComment(rs.getString("COMMENT"));
review.setCreatedAt(rs.getTimestamp("CREATED_AT"));
review.setUsername(rs.getString("CREATED_BY"));
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
review.setRating(rs.getInt("RATING"));
review.setUsername(rs.getString("USERNAME"));
@ -217,9 +218,10 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
conn = this.getDBConnection();
sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID "
+ "FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND "
+ "AP_APP_RELEASE.UUID =? AND AP_APP_REVIEW.TENANT_ID = ? AND "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID, "
+ "AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? "
+ "AND AP_APP_REVIEW.TENANT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;";
statement = conn.prepareStatement(sql);
statement.setString(1, uuid);
@ -235,6 +237,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
review.setParentId(rs.getInt("PARENT_ID"));
review.setUsername(rs.getString("USERNAME"));
review.setRating(rs.getInt("RATING"));
reviews.add(review);
}
} catch (DBConnectionException e) {
@ -260,9 +263,9 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
List<Integer> reviews = new ArrayList<>();
try {
conn = this.getDBConnection();
sql = "SELECT AP_APP_COMMENT.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
sql = "SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
+ "AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_COMMENT.TENANT_ID = ?;";
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_REVIEW.TENANT_ID = ?;";
statement = conn.prepareStatement(sql);
statement.setString(1, uuid);
statement.setInt(2, tenantId);
@ -353,7 +356,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
PreparedStatement statement = null;
try {
conn = this.getDBConnection();
sql = "DELETE FROM AP_APP_REVIEW WHERE ID=? AND USERNAME = ?);";
sql = "DELETE FROM AP_APP_REVIEW WHERE ID=? AND USERNAME = ?;";
statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId);
statement.setString(2, username);

@ -297,7 +297,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE AP_APP_RELEASE SET RATING = ?,RATED_USERS = ? WHERE UUID = ?;";
String sql = "UPDATE AP_APP_RELEASE SET RATING = ?, RATED_USERS = ? WHERE UUID = ?;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
@ -327,7 +327,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
PreparedStatement statement = null;
ResultSet resultSet = null;
Rating rating = null;
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ? AND TENANT_D=?;";
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ? AND TENANT_ID=?;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
@ -466,6 +466,40 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
}
}
@Override
public boolean verifyReleaseExistenceByUuid(String uuid, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by application release uuid: " + uuid);
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql =
"SELECT AR.ID AS RELEASE_ID FROM AP_APP_RELEASE AS AR WHERE AR.UUID = ? AND AR.TENANT_ID = ?;";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application release with the application UUID: "
+ uuid);
}
return rs.next();
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred when executing query to get application release details for App release uuid: "
+ uuid, e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
/**
* This method is capable to construct {@link ApplicationRelease} and return the object
*

@ -25,16 +25,15 @@ import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
@ -64,44 +63,38 @@ public class ReviewManagerImpl implements ReviewManager {
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
}
@Override public boolean addReview(Review review, String uuid)
throws ReviewManagementException, RequestValidatingException {
@Override
public boolean addReview(Review review, String uuid) throws ReviewManagementException, NotFoundException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isSuccess = false;
try {
ConnectionManagerUtil.openDBConnection();
Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId);
if (!this.applicationReleaseDAO.verifyReleaseExistenceByUuid(uuid, tenantId)){
throw new NotFoundException("Couldn't find application release for the application UUID: " + uuid);
}
Review existingReview = this.reviewDAO.haveUerCommented(uuid, username, tenantId);
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)
&& review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid, tenantId);
new Thread(task).start();
isSuccess = updateReview(review, existingReview.getId(), uuid, existingReview);
} else if (review.getRating() > 0) {
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid);
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid, tenantId);
new Thread(task).start();
review.setUsername(username);
ConnectionManagerUtil.beginDBTransaction();
isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
if (isSuccess) {
ConnectionManagerUtil.commitDBTransaction();
} else {
ConnectionManagerUtil.rollbackDBTransaction();
}
}
return isSuccess;
} catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"DB Connection error occurs ,Review for application release with UUID: " + uuid + " is failed", e);
} catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"Transaction Management Exception occurs,Review for application release with UUID:" + uuid +
" is failed ", e);
} catch (UserStoreException e) {
} catch (UserStoreException e) {
throw new ReviewManagementException("Error occured while verifying user's permission to update the review.",
e);
} catch (ApplicationManagementDAOException e) {
throw new ReviewManagementException(
"Error occured while verifying whether application release is exists or not.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -112,18 +105,20 @@ public class ReviewManagerImpl implements ReviewManager {
throws ReviewManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isConnectionOpen = false;
if (log.isDebugEnabled()) {
log.debug("Review updating request is received for the review id " + reviewId);
}
try {
if (existingReview == null) {
ConnectionManagerUtil.openDBConnection();
isConnectionOpen = true;
existingReview = this.reviewDAO.getReview(reviewId);
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) {
if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Review finalExistingReview = existingReview;
Runnable task = () -> calculateRating(review.getRating(), finalExistingReview.getRating(),
uuid);
uuid, tenantId);
new Thread(task).start();
}
} else {
@ -138,28 +133,21 @@ public class ReviewManagerImpl implements ReviewManager {
if (review.getRating() == 0) {
review.setRating(existingReview.getRating());
}
ConnectionManagerUtil.beginDBTransaction();
if (this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
ConnectionManagerUtil.rollbackDBTransaction();
return false;
return this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1;
} catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("Error occured while updating review with review id " + reviewId + ".",
throw new ReviewManagementException("Error occured while getting review with review id " + reviewId + ".",
e);
} catch (DBConnectionException e) {
throw new ReviewManagementException(
"DB Connection error occurs updating review with review id " + reviewId + ".", e);
} catch (TransactionManagementException e) {
throw new ReviewManagementException(
"Transaction management error occurs when updating review with review id " + reviewId + ".", e);
} catch (UserStoreException e) {
throw new ReviewManagementException(
"Error occured while verifying user's permission to update the review. review id: " + reviewId
+ ".", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
if (isConnectionOpen) {
ConnectionManagerUtil.closeDBConnection();
}
}
}
@ -221,25 +209,16 @@ public class ReviewManagerImpl implements ReviewManager {
throw new ReviewDoesNotExistException(
"Cannot delete a non-existing review for the application with review id" + reviewId);
}
Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid);
Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid, tenantId);
new Thread(task).start();
ConnectionManagerUtil.beginDBTransaction();
if (isAuthorizedUser(username, existingReview.getUsername(), tenantId)
&& this.reviewDAO.deleteReview(username, reviewId) == 1) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
ConnectionManagerUtil.rollbackDBTransaction();
return false;
return isAuthorizedUser(username, existingReview.getUsername(), tenantId)
&& this.reviewDAO.deleteReview(username, reviewId) == 1;
} catch (DBConnectionException e) {
throw new ReviewManagementException(
"DB Connection error occurs deleting review with review id " + reviewId + ".", e);
} catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("Error occured while deleting review with review id " + reviewId + ".",
e);
} catch (TransactionManagementException e) {
throw new ReviewManagementException(
"Transaction Management Exception occurs deleting review with review id " + reviewId + ".", e);
} catch (UserStoreException e) {
throw new ReviewManagementException(
"User-store exception while checking whether the user " + username + " of tenant " + tenantId
@ -261,7 +240,7 @@ public class ReviewManagerImpl implements ReviewManager {
}
List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid, tenantId);
TreeMap<Integer, Integer> ratingVariety = rating.getRatingVariety();
TreeMap<Integer, Integer> ratingVariety = new TreeMap<>();
for (Integer ratingVal : ratingValues) {
if (ratingVariety.containsKey(ratingVal)) {
ratingVariety.replace(ratingVal, ratingVariety.get(ratingVal) + 1);
@ -290,43 +269,42 @@ public class ReviewManagerImpl implements ReviewManager {
}
}
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid, int tenantId) {
try {
ConnectionManagerUtil.beginDBTransaction();
ConnectionManagerUtil.openDBConnection();
Rating rating = this.applicationReleaseDAO.getRating(uuid, tenantId);
if (rating == null) {
log.error("Couldn't find rating for application release uuid: " + uuid);
} else {
double updatedRating;
double newTotalRating;
int numOfUsers = rating.getNoOfUsers();
double currentRating = rating.getRatingValue() * numOfUsers;
if (oldRatingVal == -12345) {
updatedRating = (currentRating + newRatingVal) / (numOfUsers + 1);
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers + 1);
newTotalRating = currentRating + newRatingVal;
numOfUsers++;
} else if (newRatingVal == 0) {
updatedRating = (currentRating - newRatingVal) / (numOfUsers - 1);
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers - 1);
newTotalRating = currentRating - newRatingVal;
numOfUsers--;
} else {
double tmpVal;
tmpVal = currentRating - oldRatingVal;
updatedRating = (tmpVal + newRatingVal) / numOfUsers;
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
newTotalRating = tmpVal + newRatingVal;
}
if (numOfUsers == 0) {
updatedRating = 0;
} else {
updatedRating = newTotalRating / numOfUsers;
}
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
}
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error("Error occured while updated the rating value of the application release UUID: " + uuid);
} catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error(
"Transaction Management Exception occured while updated the rating value of the application release UUID: "
+ uuid);
log.error("Error occured while getting the rating value of the application release UUID: " + uuid, e);
} catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error("DB Connection error occured while updated the rating value of the application release UUID: "
+ uuid + " can not get.");
+ uuid + " can not get.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}

@ -16,13 +16,13 @@
* under the License.
*/
package org.wso2.carbon.device.application.mgt.publisher.api;
package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import javax.ws.rs.core.Response;
@ -37,6 +37,7 @@ public class APIUtil {
private static ApplicationManager applicationManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
private static ReviewManager reviewManager;
public static ApplicationManager getApplicationManager() {
if (applicationManager == null) {
@ -115,4 +116,27 @@ public class APIUtil {
return subscriptionManager;
}
/**
* To get the Review Manager from the osgi context.
* @return ReviewManager instance in the current osgi context.
*/
public static ReviewManager getReviewManager() {
if (reviewManager == null) {
synchronized (APIUtil.class) {
if (reviewManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
reviewManager =
(ReviewManager) ctx.getOSGiService(ReviewManager.class, null);
if (reviewManager == null) {
String msg = "Review Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return reviewManager;
}
}

@ -22,16 +22,16 @@
<parent>
<artifactId>application-mgt</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.publisher.api</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>WSO2 Carbon - Application Management API</name>
<description>WSO2 Carbon - Application Management API</description>
<name>WSO2 Carbon - Application Management Publisher API</name>
<description>WSO2 Carbon - Application Management Publisher API</description>
<url>http://wso2.org</url>
<build>
@ -218,12 +218,8 @@
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.addons</artifactId>
</dependency>
</dependencies>
</project>

@ -1,41 +0,0 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.publisher.api;
import javax.servlet.*;
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,55 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.StreamingOutput;
/**
* 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,92 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.publisher.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.wso2.carbon.device.application.mgt.common.jaxrs.AnnotationExclusionStrategy;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
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 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,73 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.wso2.carbon.device.application.mgt.common.jaxrs.AnnotationExclusionStrategy;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
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;
/**
* 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,120 +0,0 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.publisher.api;
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.*;
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) {
}
}

@ -33,13 +33,12 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import java.util.List;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;

@ -25,7 +25,7 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;

@ -48,17 +48,17 @@
<property name="scan" value="true"/>
</bean>
<bean id="ValidationInterceptor" class="org.wso2.carbon.device.application.mgt.publisher.api.ValidationInterceptor"/>
<bean id="org.wso2.carbon.device.application.mgt.addons.ValidationInterceptor" class="org.wso2.carbon.device.application.mgt.addons.ValidationInterceptor"/>
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.publisher.api.services.impl.ApplicationManagementAPIImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.publisher.api.JSONMessageHandler"/>
<bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.publisher.api.MultipartCustomProvider"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.addons.JSONMessageHandler"/>
<bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.addons.MultipartCustomProvider"/>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="ValidationInterceptor"/>
<ref bean="org.wso2.carbon.device.application.mgt.addons.ValidationInterceptor"/>
</cxf:inInterceptors>
</cxf:bus>

@ -73,7 +73,7 @@
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>org.wso2.carbon.device.application.mgt.publisher.api.ApiOriginFilter</filter-class>
<filter-class>org.wso2.carbon.device.application.mgt.addons.ApiOriginFilter</filter-class>
</filter>
<filter>

@ -22,12 +22,12 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>application-mgt</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.publisher.ui</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<name>WSO2 Carbon - Application Management Publisher UI</name>
<description>WSO2 Carbon - Application Management Publisher UI React Application</description>
<url>http://wso2.org</url>

@ -22,16 +22,16 @@
<parent>
<artifactId>application-mgt</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.store.api</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>WSO2 Carbon - Application Management API</name>
<description>WSO2 Carbon - Application Management API</description>
<name>WSO2 Carbon - Application Management Store API</name>
<description>WSO2 Carbon - Application Management Store API</description>
<url>http://wso2.org</url>
<build>
@ -173,6 +173,10 @@
<artifactId>org.wso2.carbon.device.application.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.addons</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
@ -232,10 +236,6 @@
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>

@ -1,120 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.store.api;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import javax.ws.rs.core.Response;
/**
* Holds util methods required for Application-Mgt API component.
*/
public class APIUtil {
private static Log log = LogFactory.getLog(APIUtil.class);
private static ApplicationManager applicationManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
public static ApplicationManager getApplicationManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationManager applicationManager = (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
if (applicationManager == null) {
String msg = "Application Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return applicationManager;
}
/**
* To get the Application Storage Manager from the osgi context.
*
* @return ApplicationStoreManager instance in the current osgi context.
*/
public static ApplicationStorageManager getApplicationStorageManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationStorageManager applicationStorageManager = (ApplicationStorageManager) ctx
.getOSGiService(ApplicationStorageManager.class, null);
if (applicationStorageManager == null) {
String msg = "Application Storage Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return applicationStorageManager;
}
/**
* To get the Subscription Manager from the osgi context.
*
* @return SubscriptionManager instance in the current osgi context.
*/
public static SubscriptionManager getSubscriptionManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
SubscriptionManager subscriptionManager = (SubscriptionManager) ctx
.getOSGiService(SubscriptionManager.class, null);
if (subscriptionManager == null) {
String msg = "Subscription Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return subscriptionManager;
}
/**
* To get the Review Manager from the osgi context.
*
* @return ReviewManager instance in the current osgi context.
*/
public static ReviewManager getReviewManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ReviewManager reviewManager = (ReviewManager) ctx.getOSGiService(ReviewManager.class, null);
if (reviewManager == null) {
String msg = "Comments Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return reviewManager;
}
public static Response getResponse(Exception ex, Response.Status status) {
return getResponse(ex.getMessage(), status);
}
public static Response getResponse(String message, Response.Status status) {
ErrorResponse errorMessage = new ErrorResponse();
errorMessage.setMessage(message);
if (status == null) {
status = Response.Status.INTERNAL_SERVER_ERROR;
}
errorMessage.setCode(status.getStatusCode());
return Response.status(status).entity(errorMessage).build();
}
}

@ -1,81 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
/**
* Represents a single error item in the error response.
*/
@ApiModel(description = "Error List Item")
public class ErrorListItem {
@NotNull
private String code = null;
@NotNull
private String message = null;
@ApiModelProperty(required = true, value = "")
@JsonProperty("code")
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public ErrorListItem() {
}
public ErrorListItem(String code, String msg) {
this.code = code;
this.message = msg;
}
/**
* Description about individual errors occurred
*/
@ApiModelProperty(required = true, value = "Description about individual errors occurred")
@JsonProperty("message")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("errorItem {\n");
sb.append(" code: ").append(code).append("\n");
sb.append(" message: ").append(message).append("\n");
sb.append("}\n");
return sb.toString();
}
}

@ -1,99 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorListItem;
import java.util.ArrayList;
import java.util.List;
/**
* This represents a response that need to be send back to the client, when the request cannot be completed
* successfully.
*/
@ApiModel(description = "Error Response")
public class ErrorResponse {
private Integer code = null;
private String message = null;
private String description = null;
private String moreInfo = null;
private List<ErrorListItem> errorItems = new ArrayList<>();
@JsonProperty(value = "code")
@ApiModelProperty(required = true, value = "")
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
@JsonProperty(value = "message")
@ApiModelProperty(required = true, value = "ErrorResponse message.")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@JsonProperty(value = "description")
@ApiModelProperty(value = "A detail description about the error message.")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@JsonProperty(value = "moreInfo")
@ApiModelProperty(value = "Preferably an url with more details about the error.")
public String getMoreInfo() {
return moreInfo;
}
public void setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
}
public void addErrorListItem(ErrorListItem item) {
this.errorItems.add(item);
}
/**
* If there are more than one error list them out. \nFor example, list out validation errors by each field.
*/
@JsonProperty(value = "errorItems")
@ApiModelProperty(value = "If there are more than one error list them out. \n" +
"For example, list out validation errors by each field.")
public List<ErrorListItem> getErrorItems() {
return errorItems;
}
public void setErrorItems(List<ErrorListItem> error) {
this.errorItems = error;
}
}

@ -31,7 +31,7 @@ import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;

@ -31,7 +31,7 @@ import io.swagger.annotations.ApiResponses;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Review;
import javax.validation.Valid;
import javax.ws.rs.Path;

@ -22,13 +22,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationManagementAPI;
import javax.validation.Valid;

@ -21,19 +21,18 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.Path;
@ -81,18 +80,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@ApiParam Review review,
@PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager();
ApplicationManager applicationManager = APIUtil.getApplicationManager();
Application application;
try {
application = applicationManager.getApplicationByRelease(uuid);
if (application.getApplicationReleases().isEmpty()){
String msg = "Couldn't Found an one application release for the UUID: " + uuid;
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
if (application.getApplicationReleases().size()>1){
String msg = "Found more than one application release for the UUID: " + uuid;
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
boolean isReviewCreated = reviewManager.addReview(review, uuid);
if (isReviewCreated) {
return Response.status(Response.Status.CREATED).entity(review).build();
@ -101,18 +89,23 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).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 (ReviewManagementException e) {
String msg = "Error occurred while creating the review";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
log.error("Error occured while getting the application for application UUID: " + uuid);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("").build();
} catch (RequestValidatingException e) {
String msg = "Error occurred while adding for application release. UUID of the application release: " + uuid;
String msg =
"Error occurred while adding for application release. UUID of the application release: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occured while accessing application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}

@ -22,11 +22,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse;
import org.wso2.carbon.device.application.mgt.common.EnterpriseInstallationDetails;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.SubscriptionManagementAPI;
import org.wso2.carbon.device.application.mgt.common.InstallationDetails;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import javax.validation.Valid;
import javax.ws.rs.POST;

@ -49,19 +49,19 @@
<property name="scan" value="true"/>
</bean>
<bean id="ValidationInterceptor" class="org.wso2.carbon.device.application.mgt.store.api.ValidationInterceptor"/>
<bean id="org.wso2.carbon.device.application.mgt.addons.ValidationInterceptor" class="org.wso2.carbon.device.application.mgt.addons.ValidationInterceptor"/>
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.ApplicationManagementAPIImpl"/>
<bean id="reviewMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.ReviewManagementAPIImpl" />
<bean id="subscriptionMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.SubscriptionManagementAPIImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.store.api.JSONMessageHandler"/>
<bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.store.api.MultipartCustomProvider"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.addons.JSONMessageHandler"/>
<bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.addons.MultipartCustomProvider"/>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="ValidationInterceptor"/>
<ref bean="org.wso2.carbon.device.application.mgt.addons.ValidationInterceptor"/>
</cxf:inInterceptors>
</cxf:bus>

@ -73,7 +73,7 @@
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>org.wso2.carbon.device.application.mgt.store.api.ApiOriginFilter</filter-class>
<filter-class>org.wso2.carbon.device.application.mgt.addons.ApiOriginFilter</filter-class>
</filter>
<filter>

@ -22,27 +22,11 @@ import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.testng.Assert;
import org.testng.IObjectFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test;
import org.wso2.carbon.device.application.mgt.common.Review;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.impl.ReviewManagementAPIImpl;
import org.wso2.carbon.device.application.mgt.store.api.services.util.CommentMgtTestHelper;
import javax.ws.rs.core.Response;
import static org.mockito.MockitoAnnotations.initMocks;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
@PowerMockIgnore("javax.ws.rs.*")
@SuppressStaticInitializationFor({

@ -24,10 +24,10 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>application-mgt</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<artifactId>org.wso2.carbon.device.application.mgt.store.ui</artifactId>
<version>3.1.40-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<dependencies>
</dependencies>

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ you may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<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>org.wso2.carbon.devicemgt</groupId>
<version>3.0.46-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.ui</artifactId>
<packaging>pom</packaging>
<version>3.0.46-SNAPSHOT</version>
<name>WSO2 Carbon - Application Management Base UI</name>
<description>WSO2 Carbon - Application Management Base UI</description>
<url>http://wso2.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<finalName>${project.artifactId}-${carbon.device.mgt.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/assembly/src.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -1,48 +0,0 @@
<!--
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>src</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>${basedir}/src</baseDirectory>
<fileSets>
<fileSet>
<!-- CDMF base app -->
<directory>${basedir}/src/main/resources/jaggeryapps/application-mgt</directory>
<outputDirectory>/jaggeryapps/application-mgt/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<!-- UUF framework app -->
<directory>${basedir}/src/main/resources/jaggeryapps/uuf-template-app</directory>
<outputDirectory>/jaggeryapps/appmgt-uuf-template-app/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<directory>${basedir}/src/main/resources/jaggery-modules</directory>
<outputDirectory>/jaggery-modules/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>

@ -1,38 +0,0 @@
<module name="utils" xmlns="http://wso2.org/projects/jaggery/module.xml">
<script>
<name>reflection</name>
<path>scripts/reflection/reflection.js</path>
</script>
<script>
<name>file</name>
<path>scripts/file/file.js</path>
</script>
<script>
<name>patterns</name>
<path>scripts/patterns/patterns.js</path>
</script>
<script>
<name>xml</name>
<path>scripts/xml/xml.js</path>
</script>
<script>
<name>request</name>
<path>scripts/request/request.js</path>
</script>
<script>
<name>response</name>
<path>scripts/response/response.js</path>
</script>
<script>
<name>time</name>
<path>scripts/time/time.js</path>
</script>
<script>
<name>url</name>
<path>scripts/url/url.js</path>
</script>
<script>
<name>exception</name>
<path>scripts/exception/exception.js</path>
</script>
</module>

@ -1,62 +0,0 @@
/*
* Copyright (c) WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed 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.
*/
/**
* Description: The response of the currently invoked api enpoint is organized
*/
var exception = {};
var log = new Log('exception_module');
(function(exception) {
/**
*
* @param message The exception description
* @param code HTTP STATUS CODE related to the exception
* @return The error object
*/
exception.buildExceptionObject = function(message, code) {
var error = {};
error.message = message;
error.code = code;
return error;
};
exception.handleError = function (exception, type, code){
var constants = require('rxt').constants;
if (type == constants.THROW_EXCEPTION_TO_CLIENT) {
log.debug(exception);
var e = exceptionModule.buildExceptionObject(exception, code);
throw e;
} else if (type == constants.LOG_AND_THROW_EXCEPTION) {
log.error(exception);
throw exception;
} else if (type == constants.LOG_EXCEPTION_AND_TERMINATE) {
log.error(exception);
var msg = 'An error occurred while serving the request!';
var e = exceptionModule.buildExceptionObject(msg, constants.STATUS_CODES.INTERNAL_SERVER_ERROR);
throw e;
} else if (type == constants.LOG_EXCEPTION_AND_CONTINUE) {
log.debug(exception);
}
else {
log.error(exception);
throw e;
}
};
}(exception))

@ -1,167 +0,0 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var file = {};
(function() {
var log = new Log('utils-file');
var CONTENT_MAP = {
'js': 'application/javascript',
'css': 'text/css',
'csv': 'text/csv',
'html': 'text/html',
'json': 'application/json',
'png': 'image/png',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'svg': 'image/svg+xml',
'ttf': 'application/x-font-ttf',
'eot': 'application/vnd.ms-fontobject',
'woff': 'application/font-woff',
'otf': 'application/x-font-otf',
'zip': 'application/zip',
'xml': 'text/xml',
'xhtml': 'application/xhtml+xml',
'pdf': 'application/pdf'
};
/**
* The function checks whether a directory contains a particular file
* @param dir The directory in which the file must be checked
* @param file A File object if the file exists,else null
*/
file.getFileInDir = function(dir, fileName) {
var isFilePresent = false;
var files = dir.listFiles();
for (var index in files) {
if (files[index].getName() == fileName) {
return files[index];
}
}
return null;
};
/**
* The function returns the file extension of a filename
* @param file
* @return: The extension of the file
*/
file.getExtension = function(file) {
var baseFileName = file.getName();
//Break up the name by .
var baseNameComponents = baseFileName.split('.');
var extension = baseNameComponents[baseNameComponents.length - 1];
return extension;
};
/**
* The function obtains the MIME type based on the extension
* @param The extension
* @return The mime type
*/
file.getMimeType = function(extension) {
return CONTENT_MAP[extension];
};
/**
* The function returns the name of the file without the file extension
* @param file A file object
* @return: The name of the file without the extension
*/
file.getFileName = function(file) {
//Get the name of the file
var baseFileName = file.getName();
//Break up the name by .
var baseNameComponents = baseFileName.split('.');
//Get all of the components except the last one
baseNameComponents.splice(baseNameComponents.length - 1, 1);
return baseNameComponents.join('.');
};
/**
* The function returns the contents of a directory as a JSON object.The name of the
* file is used as the property names without the extensions.
* NOTE: The method will not traverse sub folders.
* @param The directory to be inspected
* @return A JSON object which contains the files in the directory
*/
file.getDirectoryContents = function(dir) {
var dirContents = {};
//Check if it is a directory
if (!dir.isDirectory()) {
log.info('Not a directory');
return dirContents;
}
//Obtain a list of all files
var files = this.getAllFiles(dir);
var name;
log.info('Files: ' + files);
//Create the directory object with each file been a property
for (var index in files) {
dirContents[this.getFileName(files[index])] = files[index];
}
return dirContents;
};
/**
* The function obtains a list of files that are not directories
* @param dir The directory to be inspected
* @return An array with all of the files in the directory
*/
file.getAllFiles = function(dir) {
var filesInDir = [];
if (!dir.isDirectory()) {
return filesInDir;
}
//Obtain a list of all files
var files = dir.listFiles();
for (var index in files) {
log.info('Checking file: ' + files[index].getName());
//Check if the file is a directory
if (!files[index].isDirectory()) {
filesInDir.push(files[index]);
}
}
return filesInDir;
};
/**
* The function returns a list of all file names in a directory
* @param dir The directory to be inspected
* @return {An array containing the name of all files in a directory
*/
file.getAllFileNames = function(dir) {
var files = dir.listFiles();
var list = [];
var fileName;
for (var index in files) {
if (files[index].isDirectory()) {
fileName=this.getFileName(files[index].getName());
list.push(fileName);
}
}
return list;
};
/**
* The function returns a list of all sub directories in a given directory
* @param dir The root directory
* @return: An array containing all sub directories
*/
file.getAllSubDirs = function(dir) {
var files = dir.listFiles();
var subDirs = [];
for (var index in files) {
if (files[index].isDirectory()) {
subDirs.push(files[index]);
}
}
return subDirs;
};
}());

@ -1,128 +0,0 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var patterns = {};
(function () {
var DEF_ERR_ARITY = 3;
var DEF_HANDLE_ARITY = 2;
var log = new Log('utils.patterns.GenericPipe');
function GenericPipe(options) {
this.errHandlerArity = DEF_ERR_ARITY || options.errArity;
this.handlerArity = DEF_HANDLE_ARITY || options.handlerArity;
this.plugins = [];
this.finalHandler = function () {
};
}
/**
*The function registers the provided plugin
*/
GenericPipe.prototype.plug = function (plugin, options) {
var options = options || {};
//Only a function
if (plugin instanceof Function) {
this.plugins.push({
handle: plugin,
options: options
});
}
//Is it a plugin object
else if (plugin instanceof Object) {
plugin.options = options;
this.plugins.push(plugin);
}
return this;
};
GenericPipe.prototype.finally = function (plugin) {
this.finalHandler = plugin;
return this;
};
GenericPipe.prototype.resolve = function (data, req, res, session) {
var context = {};
context.req = req;
context.res = res;
context.session = session;
context.data = data;
handle(context, this.plugins, this.errHandlerArity, this.handlerArity, this.finalHandler);
};
var handle = function (context, plugins, errArity, handlerArity, finallyHandler) {
var index = 0;
var currentPlugin;
var recursiveHandle = function (err) {
currentPlugin = plugins[index];
index++;
//Check if there is a plugin
if (!currentPlugin) {
//log.warn('No plugin found at index: ' + index);
return;
}
//Populate the options object for the plugin
context.options=currentPlugin.options;;
//Check if an error has been provided
if (err) {
//Can the current plugin handle the err
if (currentPlugin.handle.length == errArity) {
try {
currentPlugin.handle(err, context,recursiveHandle);
}
catch (e) {
recursiveHandle(e);
}
}
else {
recursiveHandle(err);
}
}
//There is no error so try to invoke the current plugin
else {
if (currentPlugin.handle.length == handlerArity) {
try {
currentPlugin.handle(context,recursiveHandle);
} catch (e) {
recursiveHandle(e);
}
}
else {
recursiveHandle();
}
}
};
recursiveHandle();
finallyHandler(context);
};
patterns.GenericPipe = GenericPipe;
}());

@ -1,230 +0,0 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var reflection = {};
/**
* Description: The script encapsulates any reflection related utility functions
*/
(function() {
var log = new Log('utils-reflection');
reflection.copyPropKeys = function(from, to) {
for (var key in from) {
if (from.hasOwnProperty(key)) {
to[key] = '';
}
}
return to;
};
/**
* The function recursively copies all property keys in an object
* @param from
* @param to
*/
reflection.copyAllPropKeys = function(from, to) {
recurse(from, to, function(from, to, key) {
if (from[key] instanceof Object) {
to[key] = from[key];
} else {
to[key] = null;
}
});
};
reflection.copyAllPropValues = function(from, to) {
recurse(from, to, function(from, to, key) {
//Create an instance if the property does not exist
if (!to[key]) {
to[key] = {};
}
//Copy the values over
if (!(from[key] instanceof Object)) {
to[key] = from[key];
} else {
log.debug('Not copying values of key: ' + key);
}
});
};
/**
* The function will only copy public properties
* @param from
* @param to
*/
reflection.copyPublicPropValues = function(from, to) {
recurse(from, to, function(from, to, key) {
//Ignore any hidden properties
if (key.charAt(0) == '_') {
log.warn('Drop key: ' + key);
return;
}
//Create an instance if the property does not exist
if (!to[key]) {
to[key] = {};
}
//Copy the values over
if (!(from[key] instanceof Object)) {
to[key] = from[key];
} else {
log.warn('Not copying values of key: ' + key);
}
});
};
reflection.inspect = function(from, to, cb) {
recurse(from, to, cb);
};
/**
* The function recursively traverses an object and then invokes the provided
* callback
* @param root
* @param clone
* @param cb
*/
var recurse = function(root, clone, cb) {
var key;
//Check if the root is an object
if (!(root instanceof Object)) {
return;
} else {
var keys = Object.keys(root);
//Go through all the other keys in the current root
for (var index in keys) {
key = keys[index];
cb(root, clone, key);
recurse(root[key], clone[key], cb);
}
}
};
reflection.copyProps = function(from, to) {
for (var key in from) {
if (from.hasOwnProperty(key)) {
to[key] = from[key];
}
}
return to;
};
reflection.getProps = function(obj) {
var props = {};
for (var key in obj) {
if (!(obj[key] instanceof Function)) {
props[key] = obj[key];
}
}
return props;
};
reflection.printProps = function(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
log.info('key: ' + key);
}
}
};
/**
* The function determines if a property is hidden based on _
* @param key
* @returns {boolean}
*/
reflection.isHiddenProp = function(key) {
if (key == '') {
return false;
}
return (key.charAt(0) == '_') ? true : false;
};
var getDiff = function(a, b, diff) {};
/**
* The function calculates the differences between two simple JSON objects
* @param a The object with which b is compared
* @param b The target of the comparison
* @return An object which records the differences between the two objects
*/
reflection.diff = function(a, b) {};
/**
* The function merges the two provided objects to create a new
* object.In the case where b has the same property as a; the property of b
* will have precedence
* @param {[type]} a [description]
* @param {[type]} b [description]
* @return A new object having the properties of both object a and b
*/
reflection.merge = function(a, b) {
var newObj = {};
//Copy the properties of a first
for (var key in a) {
newObj[key] = b[key];
}
//Override with the properties of b
for (var key in b) {
newObj[key] = b[key];
}
return newObj;
};
/**
* The function allows a child class to override a select set of methods of
* a parent class.The original methods of the parent can be accessed
* using the this._super keyword
* @param {[type]} parent The parent class instance to be overriden
* @param {[type]} child The child class instance containing methods which will override the parent
*/
reflection.override = function(parent, child) {
//Make a clone of the parent
var super = parse(stringify(parent));
for (var childKey in child) {
for (var parentKey in parent) {
//Only override those methods that are common
if (childKey === parentKey) {
var parentPtr = parent[parentKey];
var childPtr = child[childKey];
//Update the clone with the old parent method
super[parentKey] = parentPtr;
parent[parentKey] = childPtr;
/*parent[parentKey] = function() {
var result=childPtr.apply(this, arguments)||null;
return result;
};*/
}
}
}
//Allow the child object to call methods of the parent
parent._super = super;
};
reflection.overrideAll=function(parent,child){
//Make a clone of the parent
var super = parse(stringify(parent));
for (var childKey in child) {
for (var parentKey in parent) {
//Only override those methods that are common
if ( (child.hasOwnProperty(childKey))&&(parent.hasOwnProperty(parentKey)) ) {
var parentPtr = parent[parentKey];
var childPtr = child[childKey];
//Update the clone with the old parent method
super[parentKey] = parentPtr;
parent[parentKey] = childPtr;
/*parent[parentKey] = function() {
var result=childPtr.apply(this, arguments)||null;
return result;
};*/
}
}
}
//Allow the child object to call methods of the parent
parent._super = super;
};
reflection.isArray = function(object) {
if (Object.prototype.toString.call(object) === '[object Array]') {
return true;
}
return false;
};
}());

@ -1,57 +0,0 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var request = {};
(function(request) {
var hasOwnProperty = function(obj, element) {
return Object.prototype.hasOwnProperty.call(obj, element);
};
var isObject = function(object) {;
return typeof object === 'object';
};
/*
* ECMA Standard (ECMA-262 : 5.1 Edition)*/
var decodes = function(encodedURI) {
return decodeURIComponent(encodedURI);
};
request.getQueryOptions = function(queryString) {
var opt={};
var sep = opt.sep || '&',
assign = opt.assign || '=',
compoArray = [];
var obj = {};
var decodedURI = decodes(queryString);
decodedURI.split(sep).forEach(function(comp) {
comp.split(assign).some(function(element, index, array) {
if (hasOwnProperty(obj, element.toString())) {
compoArray.push(obj[element]);
compoArray.push(array[1]);
obj[element] = compoArray;
} else {
Object.defineProperty(obj, element, {
enumerable: true,
writable: true,
value: array[1]
});
}
return true;
});
});
return obj;
};
}(request))

@ -1,96 +0,0 @@
/*
* Copyright (c) WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* Licensed 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.
*/
/**
* Description: The response of the currently invoked api endpoint is organized
*/
var response = {};
var log = new Log("response");
(function(response) {
/**
* Build Error response
* @param resp jaggery-response object to retrieve to client
* @param code status code
* @param message message to the client side
* @return return response
*/
response.buildErrorResponse = function(resp,code,message) {
var content={};
content.error = message;
resp = processResponse(resp,code,content);
return resp;
};
/**
* Build success response
* @param resp jaggery response object
* @param code status code
* @param data the result to client
* @return return response
*/
response.buildSuccessResponse= function(resp, code, data){
var content={};
content.data = data;
resp = processResponse(resp,code,content);
return resp;
};
/**
* process General response
* @param resp jaggery response
* @param code status code
* @param data success result
* @return resp jaggery response
*/
response.buildSuccessResponseForRxt= function(resp, code, data){
resp.status = code;
resp.content = data;
return resp;
};
/**
* General response builder
* @param resp jaggery response
* @param code status code
* @param content what ever the content to be sent as response
* @return resp jaggery response
*/
function processResponse(resp, code, content){
resp.status = code;
resp.contentType = 'application/json';
resp.content = content;
return resp;
};
/**
*
* @param resp
* @param code
* @param data
* @return The http response
*/
response.buildSuccessResponseForRxt= function(resp, code, data){
resp.contentType = 'application/json';
resp.status = code;
resp.content = data;
return resp;
};
}(response))

@ -1,35 +0,0 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var time = {};
(function(time) {
time.getCurrentTime = function(dateLength) {
var dateLength=dateLength||20;
var now = new String(new Date().valueOf());
var length = now.length;
var prefix = dateLength;
var onsetVal = '';
if (length != prefix) {
var onset = prefix - length;
for (var i = 0; i < onset; i++) {
onsetVal += '0';
}
}
return onsetVal + now;
};
}(time));

@ -1,47 +0,0 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var url = {};
(function() {
var log=new Log('utils-url');
url.popServerDetails = function(obj) {
var process = require('process');
var localIP = process.getProperty('server.host');
var httpPort = process.getProperty('http.port');
var httpsPort = process.getProperty('https.port');
var value = '';
var carbonLocalIP = process.getProperty('carbon.local.ip');
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
value = obj[key];
if ((typeof value === 'string') && value.indexOf('%https.host%') > -1) {
value=value.replace('%https.host%', 'https://' + localIP + ':' + httpsPort);
} else if ((typeof value === 'string') && value.indexOf('%http.host%') > -1) {
value=value.replace('%http.host%', 'http://' + localIP + ':' + httpPort);
} else if ((typeof value === 'string') && value.indexOf('%https.carbon.local.ip%') > -1) {
value=value.replace('%https.carbon.local.ip%', 'https://' + carbonLocalIP + ':' + httpsPort);
} else if ((typeof value === 'string') && value.indexOf('%http.carbon.local.ip%') > -1) {
value=value.replace('%http.carbon.local.ip%', 'http://' + carbonLocalIP + ':' + httpPort);
}
obj[key] = value;
}
}
return obj;
};
}(url));

@ -1,138 +0,0 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var xml = {};
(function () {
var log=new Log('util.xml')
/*
The method is used to create a JSON object using
an xml object.
@xmlElement: An xml element object to be processed
@return: A pseudo object containing the properties of the
xml element.
*/
var createJSONObject = function (xmlElement) {
var pseudo = {};
//Extract all attributes
var attributes = xmlElement.@*;
//Fill the pseudo object with the attributes of the element
for (var attributeKey in attributes) {
var attribute = attributes[attributeKey];
pseudo[attribute.localName()] = attribute.toString();
}
return pseudo;
};
/*
The function converts an E4X Xml object to a JSON object
This function has been adapted from the work of Oleg Podsechin available at
https://gist.github.com/olegp/642667
It uses a slightly modified version of his algorithm , therefore
all credit should be attributed to Oleg Podsechin.
IMPORTANT:
1. It does not create a 1..1 mapping due to the differences
between Xml and JSON.It is IMPORTANT that you verify the structure
of the object generated before using it.
2. The input xml object must not contain the xml header information
This is a known bug 336551 (Mozilla Developer Network)
Source: https://developer.mozilla.org/en/docs/E4X
Please remove the header prior to sending the xml object for processing.
@root: A starting element in an E4X Xml object
@return: A JSON object mirroring the provided Xml object
*/
var recursiveConvertE4XtoJSON = function (root) {
log.debug('Root: ' + root.localName());
//Obtain child nodes
var children = root.*;
//The number of children
var numChildren = children.length();
//No children
if (numChildren == 0) {
//Extract contents
return createJSONObject(root);
}
else {
//Create an empty object
var rootObject = createJSONObject(root);
//Could be multiple children
for (var childElementKey in children) {
var child = children[childElementKey];
log.debug('Examining child: ' + child.localName());
//If the child just contains a single value then stop
if (child.localName() == undefined) {
log.debug('Child is undefined: ' + child.toString());
//Change the object to just a key value pair
rootObject[root.localName()] = child.toString();
return rootObject;
}
//Make a recursive call to construct the child element
var createdObject = recursiveConvertE4XtoJSON(child);
log.debug('Converted object: ' + stringify(createdObject));
//Check if the root object has the property
if (rootObject.hasOwnProperty(child.localName())) {
log.debug('key: ' + child.localName() + ' already present.');
rootObject[child.localName()].push(createdObject);
}
else {
log.debug('key: ' + child.localName() + ' not present.');
rootObject[child.localName()] = [];
rootObject[child.localName()].push(createdObject);
}
}
log.debug('root: ' + root.localName());
return rootObject;
}
};
/**
* The function is used to convert an E4X xml to JSON
* @param root
*/
xml.convertE4XtoJSON = function (root) {
return recursiveConvertE4XtoJSON(root);
};
}());

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>400 - Bad request</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -1,33 +0,0 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed 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 html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bad request - Error 400</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 400</h1>
<h3>We are unable to understand the request and process it. Please re-check your request.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>401 - Unauthorized</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -1,33 +0,0 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed 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 html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Unauthorized - Error 401</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 401</h1>
<h3>You do not have permission to access this page.Please contact your administrator and request permission.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>403 - Forbidden</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -1,34 +0,0 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed 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 html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Forbidden - Error 403</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 403</h1>
<h3>We cannot process this request.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>404 - Page Not Found</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -1,33 +0,0 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed 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 html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page not found - Error 404</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 404</h1>
<h3>We can't find what you are looking for.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>405 - Method Not Allowed</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -1,33 +0,0 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed 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 html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Method not allowed - Error 405</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 405</h1>
<h3>Method not allowed.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>500 - Internal Server Error</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -1,32 +0,0 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed 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 html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Internal Server Error - Error 500</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<body>
<i class="icon-ambulance error-icon"></i>
<h1>Error 500</h1>
<h3>Something went wrong and we're trying to fix it.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -1,100 +0,0 @@
{
"displayName": "Carbon Application Management App",
"logLevel": "info",
"urlMappings": [
{
"url": "/uuf/login",
"path": "/lib/modules/auth/login.jag"
},
{
"url": "/uuf/logout",
"path": "/lib/modules/auth/logout.jag"
},
{
"url": "/uuf/sso/acs",
"path": "/lib/modules/auth/acs.jag"
},
{
"url": "/public/*",
"path": "/lib/static-files.jag"
},
{
"url": "/unit/*",
"path": "/lib/units.jag"
},
{
"url": "/*",
"path": "/lib/pages.jag"
}
],
"errorPages": {
"500": "/error-pages/error500.html",
"404": "/error-pages/error404.html",
"401": "/error-pages/error401.html",
"405": "/error-pages/error405.html",
"403": "/error-pages/error403.html",
"400": "/error-pages/error400.html"
},
"filters": [
{
"name": "ContentTypeBasedCachePreventionFilter",
"class": "org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter",
"params" : [
{"name" : "patterns", "value" : "text/html\" ,application/json\" ,text/plain"},
{"name" : "filterAction", "value" : "enforce"},
{"name" : "httpHeaders", "value" : "Cache-Control: no-store, no-cache, must-revalidate, private"}
]
},
{
"name":"HttpHeaderSecurityFilter",
"class":"org.apache.catalina.filters.HttpHeaderSecurityFilter",
"params" : [{"name" : "hstsEnabled", "value" : "false"}]
},
{
"name" : "CSRFGuard",
"class" : "org.owasp.csrfguard.CsrfGuardFilter"
}
],
"filterMappings": [
{
"name":"HttpHeaderSecurityFilter",
"url":"*"
},
{
"name" : "CSRFGuard",
"url" : "/*"
},
{
"name":"ContentTypeBasedCachePreventionFilter",
"url":"*"
}
],
"listeners" : [
{
"class" : "org.owasp.csrfguard.CsrfGuardServletContextListener"
},
{
"class" : "org.owasp.csrfguard.CsrfGuardHttpSessionListener"
}
],
"servlets" : [
{
"name" : "JavaScriptServlet",
"class" : "org.owasp.csrfguard.servlet.JavaScriptServlet"
}
],
"servletMappings" : [
{
"name" : "JavaScriptServlet",
"url" : "/csrf.js"
}
],
"contextParams" : [
{
"name" : "Owasp.CsrfGuard.Config",
"value" : "repository/conf/security/Owasp.CsrfGuard.dashboard.properties"
}
]
}

@ -1,45 +0,0 @@
{
"appName": "UUF Template App",
"cachingEnabled": false,
"debuggingEnabled": false,
"permissionRoot": "/",
"loginPage": "uuf.page.sign-in",
"adminServicesUrl": "https://${server.ip}:${server.https_port}/admin/services/",
"authModule": {
"enabled": true,
"login": {
"onSuccess": {
"script": "/app/modules/login.js",
"page": "uuf.page.home"
},
"onFail": {
"script": "/app/modules/login.js",
"page": "uuf.page.sign-in"
}
},
"logout": {
"onSuccess": {
"script": "/app/modules/logout.js",
"page": "uuf.page.sign-in"
},
"onFail": {
"script": "/app/modules/logout.js",
"page": "uuf.page.home"
}
},
"sso": {
"enabled": false,
"issuer": "uuf",
"responseSigningEnabled": true,
"keyStoreName": "repository/resources/security/wso2carbon.jks",
"keyStorePassword": "wso2carbon",
"identityProviderAlias": "wso2carbon",
"identityProviderUrl": "https://${server.ip}:${server.https_port}/samlsso",
"intermediatePage": "uuf.page.sso-intermediate"
}
},
"errorPages": {
"404": "uuf.page.error",
"default": "uuf.page.error"
}
}

@ -1,67 +0,0 @@
{{!--
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
--}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{#defineZone "title"}}WSO2 Template{{/defineZone}}</title>
{{defineZone "favicon"}}
{{defineZone "topCss"}}
{{defineZone "topJs"}}
</head>
<body>
<!-- header -->
{{defineZone "header"}}
<!-- /header -->
<!-- navbars -->
<div class="navbar-wrapper">
{{defineZone "navbars"}}
</div>
<!-- /navbars -->
<!-- sidepanes -->
{{defineZone "sidePanes"}}
<!-- /sidepanes -->
<!-- page-content-wrapper -->
<div class="page-content-wrapper">
{{defineZone "contentTitle"}}
<div class="container-fluid ">
<div class="body-wrapper">
{{defineZone "content"}}
</div>
</div>
</div>
<!-- /page-content-wrapper -->
<!-- footer -->
<footer class="footer">
<div class="container-fluid">
{{defineZone "footer"}}
</div>
</footer>
<!-- /footer -->
{{defineZone "bottomJs"}}
</body>
</html>

@ -1,56 +0,0 @@
{{!--
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
--}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{#defineZone "title"}}WSO2 Template{{/defineZone}}</title>
{{defineZone "favicon"}}
{{defineZone "topCss"}}
{{defineZone "topJs"}}
</head>
<body>
<!-- header -->
{{defineZone "header"}}
<!-- /header -->
<!-- page-content-wrapper -->
<div class="page-content-wrapper">
<div class="container-fluid ">
<div class="body-wrapper">
{{defineZone "content"}}
</div>
</div>
</div>
<!-- /page-content-wrapper -->
<!-- footer -->
<footer class="footer">
<div class="container-fluid">
{{defineZone "footer"}}
</div>
</footer>
<!-- /footer -->
{{defineZone "bottomJs"}}
</body>
</html>

@ -1,38 +0,0 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
{{#zone "title"}}Error | {{@app.conf.appName}}{{/zone}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
{{/zone}}
{{#zone "content"}}
<div class="message message-danger">
<h4><i class="icon fw fw-error"></i>An Error Occurred!</h4>
<div style="padding-left: 25px;">
<h5><b>HTTP Status : {{@page.params.status}}</b></h5>
<p style="white-space: pre-wrap;">{{@page.params.message}}</p>
</div>
</div>
{{/zone}}

@ -1,6 +0,0 @@
{
"version": "1.0.0",
"uri": "/error/default",
"layout": "uuf.layout.default",
"isAnonymous": true
}

@ -1,24 +0,0 @@
$(document).ready(function(){
$("#signInForm").validate({
rules: {
username: {
required: true,
minlength: 3
},
password: {
required: true,
minlength: 3
}
},
messages: {
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 3 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 3 characters long"
}
}
});
});

@ -1,63 +0,0 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
{{#zone "title"}}Sign In | {{@app.conf.appName}}{{/zone}}
{{~#zone "content"}}
<div class="col-sm-7 col-md-4 center-block" style="float: none; margin-top: 10%;">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
{{#defineZone "signIn-title" scope="protected"}}Sign In to UUF Template App{{/defineZone}}
</h4>
</div>
<div class="panel-body">
{{#if message}}
<div id="_uuf_login-error-msg" class="alert alert-danger">
<i class="icon fw fw-warning"></i> {{message}}!
</div>
{{/if}}
<form id="signInForm" method="POST"
class="{{defineZone "signInForm-class" scope="protected"}}"
action="{{#defineZone "signInForm-action" scope="protected"}}{{@app.context}}/uuf/login{{/defineZone}}">
<div class="form-group">
<input type="text" name="username" class="form-control"
placeholder="User Name" required="required" autofocus="autofocus" />
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" autocomplete="off"
placeholder="Password" required="required" />
</div>
{{#if referer}}
<input type="hidden" name="referer" value="{{referer}}" />
{{/if}}
<div class="form-group" style="padding-top: 10px;">
<input type="submit" name="signInBtn" class="btn btn-primary btn-block"
value="Sign In" />
</div>
{{defineZone "signInForm-below" scope="protected"}}
</form>
</div>
</div>
</div>
{{/zone}}
{{! sign-in form validation}}
{{~unit "uuf.unit.lib.form-validation"}}
{{~#zone "bottomJs"}}
{{~js "js/sign-in-validations.js"}}
{{/zone}}

@ -1,30 +0,0 @@
function onRequest(context) {
var authModuleConfigs = context.app.conf["authModule"];
if (authModuleConfigs && (authModuleConfigs["enabled"].toString() == "true")) {
// Auth module is enabled.
if (context.user) {
// User is already logged in.
response.sendRedirect(context.app.context + "/");
exit();
} else {
// User is not logged in.
var ssoConfigs = authModuleConfigs["sso"];
if (ssoConfigs && (ssoConfigs["enabled"].toString() == "true")) {
// SSO is enabled in Auth module.
var redirectUri = context.app.context + "/uuf/login";
var queryString = request.getQueryString();
if (queryString && (queryString.length > 0)) {
redirectUri = redirectUri + "?" + queryString;
}
response.sendRedirect(encodeURI(redirectUri));
exit();
} else {
// Generic login process is enabled.
return {
message: request.getParameter("error"),
referer: request.getParameter("referer")
};
}
}
}
}

@ -1,18 +0,0 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
{{! This template won't be rendered. So nothing is here }}

@ -1,16 +0,0 @@
function onRequest(context) {
var authModuleConfigs = context.app.conf["authModule"];
if (authModuleConfigs && (authModuleConfigs["enabled"].toString() == "true")) {
// Auth module is enabled.
if (context.user) {
// User is logged in.
response.sendRedirect(context.app.context + "/uuf/logout");
exit();
} else {
// User is already logged out.
response.sendRedirect(context.app.context + "/");
exit();
}
}
}

@ -1,45 +0,0 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
{{#zone "title"}}Sign In | {{@app.conf.appName}}{{/zone}}
{{unit "uuf.unit.theme"}}
{{unit "uuf.unit.header.logo"}}{{unit "uuf.unit.header"}}
{{unit "uuf.unit.footer"}}
{{#zone "content"}}
<div class="jumbotron">
<p>
You are now being redirected to Identity Server. If the redirection fails, please click
on the button below.
</p>
<div>
<form method="post" action="{{@page.params.identityProviderUrl}}">
<input type="hidden" name="SAMLRequest"
value="{{@page.params.encodedSAMLAuthRequest}}" />
<input type="hidden" name="RelayState" value="{{@page.params.relayState}}" />
<input type="hidden" name="SSOAuthSessionID" value="{{@page.params.sessionId}}" />
<button type="submit" class="btn btn-primary">Redirect manually</button>
</form>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script type="text/javascript">document.forms[0].submit();</script>
{{/zone}}

@ -1,27 +0,0 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
<div {{#if @unit.params.id}}id="{{@unit.params.id}}" {{/if~}}
class="alert alert-{{@unit.params.type}}" role="alert">
<i class="icon fw fw-{{icon}}"></i>
<strong>{{@unit.params.title}}</strong> {{{@unit.params.message}}}
{{#if @unit.params.dismissable}}
<button type="button" class="close" aria-label="close" data-dismiss="alert">
<span aria-hidden="true"><i class="fw fw-cancel"></i></span>
</button>
{{/if}}
</div>

@ -1,15 +0,0 @@
function onRequest(context) {
var type = context.unit.params.type;
switch (type) {
case "success":
return {icon: "ok"};
case "info":
return {icon: "info"};
case "warning":
return {icon: "warning"};
case "danger":
return {icon: "error"};
default:
return {icon: "ok"};
}
}

@ -1,24 +0,0 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
{{#zone "favicon"}}
{{#if isCloud}}
<link rel="shortcut icon" href="{{@unit.publicUri}}/img/cloud-favicon.png" />
{{else}}
<link rel="shortcut icon" href="{{@unit.publicUri}}/img/favicon.png" />
{{/if}}
{{/zone}}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save