Adding refactoring as per maven checkstyle plugin

merge-requests/7/head
megala21 7 years ago
parent 5a8bf10d5a
commit 7fd7fbb30e

@ -23,7 +23,11 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import javax.ws.rs.core.Response;

@ -19,11 +19,11 @@
package org.wso2.carbon.device.application.mgt.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.

@ -23,6 +23,13 @@ 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;
@ -31,12 +38,12 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
/**
* This provider is used to change a JSON object to complex object and inversely in request and response.
*/
@Provider
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)

@ -1,3 +1,21 @@
/*
* 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.api;
import com.google.gson.Gson;
@ -5,64 +23,51 @@ 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.apache.cxf.jaxrs.provider.MultipartProvider;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.jaxrs.AnnotationExclusionStrategy;
import javax.mail.Multipart;
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.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.Provider;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* 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 true;
return !aClass.equals(Attachment.class);
}
public Object readFrom(Class<Object> c, Type t, Annotation[] anns, MediaType mt, 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 getGson().fromJson(obj, t);
}
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();
@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);
}
return gson;
String jsonString = result.toString();
JsonObject obj = new JsonParser().parse(jsonString).getAsJsonObject();
return gson.fromJson(obj, type);
}
}

@ -24,6 +24,9 @@ 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 {

@ -25,6 +25,10 @@ import io.swagger.annotations.ApiModelProperty;
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 {

@ -483,6 +483,7 @@ public interface ApplicationManagementAPI {
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response createApplicationRelease(
@ApiParam(
name = "UUID",

@ -31,8 +31,8 @@ import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.Platform;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@ -40,8 +40,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* Lifecycle management related APIs.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
@ -139,7 +141,8 @@ public interface LifecycleManagementAPI {
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
"Empty body because the client already has the latest version of the requested "
+ "resource."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred adding a lifecycle state.",

@ -36,6 +36,11 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationRelease
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -48,11 +53,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Implementation of Application Management related APIs.

@ -25,15 +25,18 @@ import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
/**
* Lifecycle Management related jax-rs APIs.
*/
@Path("/lifecycles")
public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {

@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map;
/**
* Application represents the an Application in Application Store
* Application represents the an Application in Application Store.
*/
public class Application {
@ -253,7 +253,7 @@ public class Application {
@Override
public String toString() {
return "UUID : " + uuid + "\tIdentifier : " + identifier + "\tName : " + name + "\tShort Description : " +
shortDescription + "\tLifecycle State : " + currentLifecycle.getLifecycleState() ;
return "UUID : " + uuid + "\tIdentifier : " + identifier + "\tName : " + name + "\tShort Description : "
+ shortDescription + "\tLifecycle State : " + currentLifecycle.getLifecycleState();
}
}

@ -22,7 +22,7 @@ package org.wso2.carbon.device.application.mgt.common.exception;
/**
* Represents the exception thrown during storing and retrieving the artifacts.
*/
public class ApplicationStorageManagementException extends ApplicationManagementException{
public class ApplicationStorageManagementException extends ApplicationManagementException {
public ApplicationStorageManagementException(String message, Throwable ex) {
super(message, ex);
}

@ -18,10 +18,12 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.*;
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.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import java.io.InputStream;
import java.util.List;
/**
@ -63,11 +65,11 @@ public interface ApplicationManager {
/**
* To change the lifecycle of the Application.
*
* @param applicationUUID UUID of the Application
* @param applicationUuid UUID of the Application
* @param lifecycleIdentifier New life-cycle that need to be changed.
* @throws ApplicationManagementException Application Management Exception.
*/
public void changeLifecycle(String applicationUUID, String lifecycleIdentifier) throws
public void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws
ApplicationManagementException;
/**

@ -34,29 +34,29 @@ public interface ApplicationReleaseManager {
/**
* To create an application release for an Application.
*
* @param UUID UUID of the Application
* @param appicationUuid UUID of the Application
* @param applicationRelease ApplicatonRelease that need to be be created.
* @return the unique id of the application release, if the application release succeeded else -1
*/
public ApplicationRelease createRelease(String UUID, ApplicationRelease applicationRelease) throws
public ApplicationRelease createRelease(String appicationUuid, ApplicationRelease applicationRelease) throws
ApplicationManagementException;
/**
* To get the application release of the Application/
* @param UUID UUID of the Application.
* @param applicationUuid UUID of the Application.
* @param version Version of the ApplicationRelease that need to be retrieved.
* @return ApplicationRelease related with particular Application UUID and version.
* @throws ApplicationManagementException ApplicationManagementException
*/
public ApplicationRelease getRelease(String UUID, String version) throws ApplicationManagementException;
public ApplicationRelease getRelease(String applicationUuid, String version) throws ApplicationManagementException;
/**
* To get all the releases of a particular Application.
* @param UUID UUID of the Application to get all the releases.
* @param applicationUuid UUID of the Application to get all the releases.
* @return the List of the Application releases related with the particular Application.
* @throws ApplicationManagementException Application Management Exception.
*/
public List<ApplicationRelease> getReleases(String UUID) throws ApplicationManagementException;
public List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException;
/**
* To make a release as the default one for an application.

@ -22,7 +22,6 @@ package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
/**

@ -1,26 +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.common.services;
/**
* This interface manages all the operations related with Application Upload.
*/
public interface ApplicationUploadManager {
}

@ -24,6 +24,9 @@ import org.wso2.carbon.device.application.mgt.core.exception.DAOException;
import java.util.List;
/**
* This is responsible for all the DAO operations related to Lifecycle state.
*/
public interface LifecycleStateDAO {
LifecycleState getLifeCycleStateByIdentifier(String identifier) throws ApplicationManagementDAOException;

@ -23,6 +23,9 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.Connection;
/**
* This class deals with getting the DB connection.
*/
public abstract class AbstractDAOImpl {
protected Connection getDBConnection() throws DBConnectionException {

@ -33,6 +33,9 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* Concrete implementation for Lifecycle related DB operations.
*/
public class GenericLifecycleStateImpl extends AbstractDAOImpl implements LifecycleStateDAO {
@Override
@ -82,7 +85,7 @@ public class GenericLifecycleStateImpl extends AbstractDAOImpl implements Lifecy
String sql = "SELECT IDENTIFIER, NAME, DESCRIPTION FROM APPM_LIFECYCLE_STATE";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while(rs.next()) {
while (rs.next()) {
LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setIdentifier(rs.getString("IDENTIFIER"));
lifecycleState.setName(rs.getString("NAME"));

@ -20,6 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
/**
* Exception thrown during the Application Management DAO operations.
*/
public class ApplicationManagementDAOException extends ApplicationManagementException {
public ApplicationManagementDAOException(String message, Throwable throwable) {

@ -17,6 +17,9 @@
*/
package org.wso2.carbon.device.application.mgt.core.exception;
/**
* This exception will be thrown when there is an issue with Lifecycle related DAO operations.
*/
public class DAOException extends Exception {
public DAOException(String message) {

@ -20,6 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
/**
* This exception will be thrown when the requested application or platform not found.
*/
public class NotFoundException extends ApplicationManagementException {
public NotFoundException(String message, Throwable throwable) {

@ -20,6 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
/**
* This exception will be thrown when the initial validation fails to perform an operation.
*/
public class ValidationException extends ApplicationManagementException {
public ValidationException(String message, Throwable throwable) {

@ -41,17 +41,19 @@ import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.io.*;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Default Concrete implementation of Application Management related implementations.
*/
public class ApplicationManagerImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
@ -184,15 +186,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public void changeLifecycle(String applicationUUID, String lifecycleIdentifier) throws
public void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws
ApplicationManagementException {
boolean isAvailableNextState = false;
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
List<LifecycleStateTransition> nextLifeCycles = getLifeCycleStates(applicationUUID);
List<LifecycleStateTransition> nextLifeCycles = getLifeCycleStates(applicationUuid);
for (LifecycleStateTransition lifecycleStateTransition : nextLifeCycles) {
if (log.isDebugEnabled()) {
log.debug("Lifecycle state of the application " + applicationUUID + " can be changed to"
log.debug("Lifecycle state of the application " + applicationUuid + " can be changed to"
+ lifecycleStateTransition.getNextState());
}
if (lifecycleStateTransition.getNextState().equalsIgnoreCase(lifecycleIdentifier)) {
@ -202,13 +204,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
if (!isAvailableNextState) {
throw new ApplicationManagementException("User " + userName + " does not have the permission to change "
+ "the lifecycle state of the application " + applicationUUID + " to lifecycle state "
+ "the lifecycle state of the application " + applicationUuid + " to lifecycle state "
+ lifecycleIdentifier);
}
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
applicationDAO.changeLifecycle(applicationUUID, lifecycleIdentifier, userName);
applicationDAO.changeLifecycle(applicationUuid, lifecycleIdentifier, userName);
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
@ -305,7 +307,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
} catch (UserStoreException e) {
throw new ApplicationManagementException("Userstore exception while checking whether user is an admin", e);
} try {
}
try {
ConnectionManagerUtil.openDBConnection();
Application application = DAOFactory.getApplicationDAO().getApplication(applicationUUID);
return application.getUser().getUserName().equals(userName)

@ -32,13 +32,16 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.util.Date;
import java.util.List;
/**
* Concrete implementation for Application Release Management related tasks.
*/
public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager {
private static Log log = LogFactory.getLog(ApplicationReleaseManagerImpl.class);
@Override
public ApplicationRelease createRelease(String UUID, ApplicationRelease applicationRelease) throws
public ApplicationRelease createRelease(String appicationUuid, ApplicationRelease applicationRelease) throws
ApplicationManagementException {
Application application = validateReleaseCreateRequest(UUID, applicationRelease);
Application application = validateReleaseCreateRequest(appicationUuid, applicationRelease);
if (log.isDebugEnabled()) {
log.debug("Application release request is received for the application " + application.toString());
}
@ -58,30 +61,31 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
}
@Override
public ApplicationRelease getRelease(String UUID, String version) throws ApplicationManagementException {
Application application = validationGetReleaseRequest(UUID);
public ApplicationRelease getRelease(String applicationUuid, String version) throws
ApplicationManagementException {
Application application = validationGetReleaseRequest(applicationUuid);
if (log.isDebugEnabled()) {
log.debug("Application release retrieval request is received for the application " +
application.toString() + " and version " + version);
}
try {
ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationReleaseDAO().getRelease(UUID, version);
return DAOFactory.getApplicationReleaseDAO().getRelease(applicationUuid, version);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public List<ApplicationRelease> getReleases(String UUID) throws ApplicationManagementException {
Application application = validationGetReleaseRequest(UUID);
public List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException {
Application application = validationGetReleaseRequest(applicationUuid);
if (log.isDebugEnabled()) {
log.debug("Request is received to retrieve all the releases related with the application " +
application.toString());
}
try {
ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationReleaseDAO().getApplicationReleases(UUID);
return DAOFactory.getApplicationReleaseDAO().getApplicationReleases(applicationUuid);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -100,18 +104,19 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
/**
* To validate the pre-request of the ApplicationRelease.
*
* @param UUID UUID of the Application.
* @param applicationUuid UUID of the Application.
* @return Application related with the UUID
*/
private Application validationGetReleaseRequest(String UUID) throws ApplicationManagementException {
if (UUID == null) {
private Application validationGetReleaseRequest(String applicationUuid) throws ApplicationManagementException {
if (applicationUuid == null) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the releases related to a particular application.");
}
Application application = DataHolder.getInstance().getApplicationManager().getApplication(UUID);
Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUuid);
if (application == null) {
throw new ApplicationManagementException("Application with UUID " + UUID + " does not exist. Cannot "
+ "retrieve the releases for a non-existing application.");
throw new ApplicationManagementException(
"Application with UUID " + applicationUuid + " does not exist. Cannot "
+ "retrieve the releases for a non-existing application.");
}
return application;
}
@ -119,30 +124,32 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
/**
* To validate a create release request to make sure all the pre-conditions satisfied.
*
* @param UUID UUID of the Application.
* @param applicationUuid UUID of the Application.
* @param applicationRelease ApplicationRelease that need to be created.
* @return the Application related with the particular Application Release
* @throws ApplicationManagementException Application Management Exception.
*/
private Application validateReleaseCreateRequest(String UUID, ApplicationRelease applicationRelease)
private Application validateReleaseCreateRequest(String applicationUuid, ApplicationRelease applicationRelease)
throws ApplicationManagementException {
if (UUID == null) {
if (applicationUuid == null) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to do the application release");
}
Application application = DataHolder.getInstance().getApplicationManager().getApplication(UUID);
Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUuid);
if (application == null) {
throw new ApplicationManagementException("Application with UUID " + UUID + " does not exist. Cannot "
+ "release an application that is not existing");
throw new ApplicationManagementException(
"Application with UUID " + applicationUuid + " does not exist. Cannot "
+ "release an application that is not existing");
}
if (applicationRelease == null || applicationRelease.getVersionName() == null){
if (applicationRelease == null || applicationRelease.getVersionName() == null) {
throw new ApplicationManagementException("ApplicationRelease version name is a mandatory parameter for "
+ "creating release. It cannot be found.");
}
if (getRelease(UUID, applicationRelease.getVersionName()) != null){
throw new ApplicationManagementException("Application Release for the Application UUID " + UUID + " "
+ "with the version " + applicationRelease.getVersionName() + " already exists. Cannot create an "
+ "application release with the same version.");
if (getRelease(applicationUuid, applicationRelease.getVersionName()) != null) {
throw new ApplicationManagementException(
"Application Release for the Application UUID " + applicationUuid + " " + "with the version "
+ applicationRelease.getVersionName() + " already exists. Cannot create an "
+ "application release with the same version.");
}
return application;
}

@ -28,13 +28,19 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
/**
* This class contains the default concrete implementation of ApplicationStorage Management.
*/
public class ApplicationStorageManagerImpl implements ApplicationStorageManager{
public class ApplicationStorageManagerImpl implements ApplicationStorageManager {
private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class);
@Override
@ -44,14 +50,15 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager{
try {
application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID);
} catch (ApplicationManagementException e) {
throw new ApplicationStorageManagementException("Exception while retrieving the application details for "
+ "the application with UUID " + applicationUUID);
throw new ApplicationStorageManagementException(
"Exception while retrieving the application details for " + "the application with UUID "
+ applicationUUID);
}
if (application == null) {
throw new ApplicationStorageManagementException("Application with UUID " + applicationUUID + " does not "
+ "exist. Cannot upload the artifacts to non-existing application.");
}
String artifactDirectoryPath = Constants.ARTIFACT_PATH + application.getId();
String artifactDirectoryPath = Constants.artifactPath + application.getId();
if (log.isDebugEnabled()) {
log.debug("Artifact Directory Path for saving the artifacts related with application " + applicationUUID
+ " is " + artifactDirectoryPath);
@ -117,7 +124,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager{
throw new ApplicationStorageManagementException("Application with UUID " + applicationUUID + " does not "
+ "exist. Cannot upload release artifacts for not existing application.");
}
String artifactDirectoryPath = Constants.ARTIFACT_PATH + application.getId();
String artifactDirectoryPath = Constants.artifactPath + application.getId();
if (log.isDebugEnabled()) {
log.debug("Artifact Directory Path for saving the application release related artifacts related with "
+ "application " + applicationUUID + " is " + artifactDirectoryPath);
@ -150,7 +157,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager{
throw new ApplicationStorageManagementException("Application with UUID " + applicationUUID + " does not "
+ "exist. Cannot retrieve release artifacts for not existing application.");
}
String artifactPath = Constants.ARTIFACT_PATH + application.getId() + File.separator + versionName;
String artifactPath = Constants.artifactPath + application.getId() + File.separator + versionName;
if (log.isDebugEnabled()) {
log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);

@ -1,29 +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.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationUploadManager;
public class ApplicationUploadManagerImpl implements ApplicationUploadManager {
public ApplicationUploadManagerImpl(String uploadPath){
}
}

@ -30,6 +30,9 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.util.List;
/**
* Concrete implementation of Lifecycle state management.
*/
public class LifecycleStateManagerImpl implements LifecycleStateManager {
private static final Log log = LogFactory.getLog(LifecycleStateManagerImpl.class);

@ -18,7 +18,16 @@
*/
package org.wso2.carbon.device.application.mgt.core.internal;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.user.core.service.RealmService;
@ -49,8 +58,6 @@ public class DataHolder {
private VisibilityManager visibilityManager;
private ApplicationUploadManager applicationUploadManager;
private ApplicationStorageManager applicationStorageManager;
private static final DataHolder applicationMgtDataHolder = new DataHolder();
@ -143,14 +150,6 @@ public class DataHolder {
this.visibilityManager = visibilityManager;
}
public void setApplicationUploadManager(ApplicationUploadManager applicationUploadManager) {
this.applicationUploadManager = applicationUploadManager;
}
public ApplicationUploadManager getApplicationUploadManager() {
return applicationUploadManager;
}
public RealmService getRealmService() {
return realmService;
}

@ -23,7 +23,16 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
@ -69,7 +78,7 @@ public class ServiceComponent {
String datasourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName();
DAOFactory.init(datasourceName);
Constants.ARTIFACT_PATH = ConfigurationManager.getInstance().getConfiguration().getArtifacts()
Constants.artifactPath = ConfigurationManager.getInstance().getConfiguration().getArtifacts()
.getBinaryLocation();
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
DataHolder.getInstance().setApplicationManager(applicationManager);
@ -108,10 +117,6 @@ public class ServiceComponent {
DataHolder.getInstance().setVisibilityTypeManager(visibilityTypeManager);
bundleContext.registerService(VisibilityTypeManager.class.getName(), visibilityTypeManager, null);
ApplicationUploadManager uploadManager = ApplicationManagementUtil.getApplicationUploadManagerInstance();
DataHolder.getInstance().setApplicationUploadManager(uploadManager);
bundleContext.registerService(ApplicationUploadManager.class.getName(), uploadManager, null);
ApplicationStorageManager applicationStorageManager = ApplicationManagementUtil
.getApplicationStorageManagerInstance();
DataHolder.getInstance().setApplicationStorageManager(applicationStorageManager);

@ -21,7 +21,16 @@ 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.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.Extension;
@ -90,12 +99,6 @@ public class ApplicationManagementUtil {
return getInstance(extension, SubscriptionManager.class);
}
public static ApplicationUploadManager getApplicationUploadManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.ApplicationUploadManager);
return getInstance(extension, ApplicationUploadManager.class);
}
public static ApplicationStorageManager getApplicationStorageManagerInstance() throws
InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();

@ -54,5 +54,8 @@ public class Constants {
public static final String[] LIFE_CYCLES = {"CREATED", "IN REVIEW", "APPROVED", "REJECTED", "PUBLISHED",
"UNPUBLISHED", "RETIRED"};
public static String ARTIFACT_PATH = "";
/**
* Path to save the Application related artifacts.
*/
public static String artifactPath = "";
}

Loading…
Cancel
Save