Merge pull request #899 from Megala21/appm_new

Refactoring
4.x.x
Megala Uthayakumar 7 years ago committed by GitHub
commit b05b392534

@ -34,12 +34,23 @@ 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.ApplicationList;
import java.util.List;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* APIs to handle application management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
@ -98,7 +109,7 @@ import java.util.List;
@Consumes(MediaType.APPLICATION_JSON)
public interface ApplicationManagementAPI {
public final static String SCOPE = "scope";
String SCOPE = "scope";
@GET
@Produces(MediaType.APPLICATION_JSON)
@ -124,8 +135,8 @@ public interface ApplicationManagementAPI {
response = ApplicationList.class),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
message = "Not Modified. Empty body because the client already has the latest version "
+ "of the requested resource."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.",
@ -134,21 +145,15 @@ public interface ApplicationManagementAPI {
Response getApplications(
@ApiParam(
name = "offset",
value = "Provide from which position apps should return",
required = false,
defaultValue = "20")
value = "Provide from which position apps should return", defaultValue = "20")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Provide how many apps it should return",
required = false,
defaultValue = "0")
value = "Provide how many apps it should return", defaultValue = "0")
@QueryParam("limit") int limit,
@ApiParam(
name = "searchQuery",
value = "Relevant search query to search on",
required = false,
defaultValue = "*")
value = "Relevant search query to search on", defaultValue = "*")
@QueryParam("searchQuery") String searchQuery
);

@ -25,7 +25,6 @@ import org.wso2.carbon.device.application.mgt.api.services.ApplicationManagement
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.User;
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.util.Constants;
@ -43,7 +42,9 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
/**
* Implementation of Application Management related APIs.
*/
@Produces({"application/json"})
@Consumes({"application/json"})
@Path("/applications")

@ -22,16 +22,12 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.api.APIUtil;
import org.wso2.carbon.device.application.mgt.api.services.LifecycleManagementAPI;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.User;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@ -18,13 +18,14 @@
*/
package org.wso2.carbon.device.application.mgt.core.config;
import org.wso2.carbon.device.application.mgt.core.deployer.Platform;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
/**
* Represents the Application Management Configuration.
*/
@XmlRootElement(name = "ApplicationManagementConfiguration")
public class Configuration {

@ -24,10 +24,13 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.File;
/**
* ConfigurationManager is responsible for the managing Application Management related configurations.
*/
public class ConfigurationManager {
private static final Log log = LogFactory.getLog(ConfigurationManager.class);

@ -18,9 +18,15 @@
*/
package org.wso2.carbon.device.application.mgt.core.config;
import javax.xml.bind.annotation.*;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Represents a extension in the application management configuration.
*/
@XmlRootElement(name = "Extension")
public class Extension {
@ -68,6 +74,9 @@ public class Extension {
return false;
}
/**
* ApplicationManagement Extensions.
*/
public enum Name {
ApplicationManager,
ApplicationReleaseManager,

@ -22,6 +22,9 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
/**
* Parameter of the extensions.
*/
@XmlRootElement(name = "Parameter")
public class Parameter {

@ -18,6 +18,9 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
/**
* This is responsible for Application Release related DAO operations.
*/
public interface ApplicationReleaseDAO {
}

@ -18,5 +18,8 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
/**
* This is responsible for Application Category related DAO operations.
*/
public interface CategoryDAO {
}

@ -21,7 +21,12 @@ package org.wso2.carbon.device.application.mgt.core.dao.common;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
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.Category;
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.common.User;
import org.wso2.carbon.device.application.mgt.core.util.JSONUtil;
import java.sql.PreparedStatement;

@ -21,21 +21,34 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
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.ApplicationRelease;
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.Pagination;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.JSONUtil;
import java.sql.*;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* This handles ApplicationDAO related operations.
*/
public class GenericApplicationDAOImpl extends AbstractDAOImpl implements ApplicationDAO {
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
@ -78,8 +91,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.setInt(14, application.getPlatform().getId());
stmt.setInt(15, application.getUser().getTenantId());
stmt.setInt(16, application.getCurrentLifecycle().getLifecycleState().getId());
stmt.setDate(17, new Date(
application.getCurrentLifecycle().getLifecycleStateModifiedAt().getTime()));
stmt.setDate(17, new Date(application.getCurrentLifecycle().getLifecycleStateModifiedAt().getTime()));
stmt.setString(18, application.getCurrentLifecycle().getGetLifecycleStateModifiedBy());
stmt.executeUpdate();
@ -88,6 +100,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
application.setId(rs.getInt(1));
}
insertApplicationTagsAndProperties(application, stmt, conn, isBatchExecutionSupported);
return application;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
@ -95,14 +108,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} finally {
Util.cleanupResources(stmt, rs);
}
return application;
}
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementDAOException {
if(log.isDebugEnabled()){
if (log.isDebugEnabled()) {
log.debug("Getting application data from the database");
log.debug(String.format("Filter: limit=%s, offset=%", filter.getLimit(), filter.getOffset()));
}
@ -185,7 +196,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override
public int getApplicationCount(Filter filter) throws ApplicationManagementDAOException {
if(log.isDebugEnabled()){
if (log.isDebugEnabled()) {
log.debug("Getting application count from the database");
log.debug(String.format("Filter: limit=%s, offset=%", filter.getLimit(), filter.getOffset()));
}
@ -276,9 +287,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Util.cleanupResources(null, rsProperties);
Util.cleanupResources(null, rsTags);
}
return application;
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application details with UUID "
+ uuid, e);
throw new ApplicationManagementDAOException(
"Error occurred while getting application details with UUID " + uuid, e);
} catch (JSONException e) {
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException e) {
@ -286,7 +298,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} finally {
Util.cleanupResources(stmt, rs);
}
return application;
}
@Override
@ -341,7 +352,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
List<LifecycleStateTransition> lifecycleStateTransitions = new ArrayList<>();
while(resultSet.next()) {
while (resultSet.next()) {
LifecycleStateTransition lifecycleStateTransition = new LifecycleStateTransition();
lifecycleStateTransition.setDescription(resultSet.getString(2));
lifecycleStateTransition.setNextState(resultSet.getString(1));
@ -361,9 +372,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override
public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException {
Connection conn = null;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
try {
@ -431,13 +441,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.executeUpdate();
insertApplicationTagsAndProperties(application, stmt, conn, isBatchExecutionSupported);
return application;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding the application", e);
} finally {
Util.cleanupResources(stmt, null);
}
return application;
}
/**
@ -509,7 +520,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override
public void deleteProperties(int applicationId) throws ApplicationManagementDAOException {
Connection conn = null;
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getDBConnection();
@ -530,10 +541,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override
public void deleteTags(int applicationId) throws ApplicationManagementDAOException {
Connection conn = null;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "DELETE FROM APPM_APPLICATION_TAG WHERE APPLICATION_ID = ?";
@ -547,7 +556,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException(
"Error occurred while deleting tags of application: " + applicationId, e);
} finally {
Util.cleanupResources(stmt, rs);
Util.cleanupResources(stmt, null);
}
}
@ -556,13 +565,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
String sql;
int id = 0;
try {
conn = this.getDBConnection();
sql += "SELECT ID FROM APPM_APPLICATION WHERE UUID = ?";
sql = "SELECT ID FROM APPM_APPLICATION WHERE UUID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid);
rs = stmt.executeQuery();
@ -576,7 +583,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} finally {
Util.cleanupResources(stmt, rs);
}
return id;
}

@ -21,12 +21,25 @@ 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.ApplicationUploadManager;
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;
import java.lang.reflect.Constructor;
/**
* This Util class is responsible for making sure single instance of each Extension Manager is used throughout for
* all the tasks.
*/
public class ApplicationManagementUtil {
private static Log log = LogFactory.getLog(ApplicationManagementUtil.class);
@ -37,7 +50,8 @@ public class ApplicationManagementUtil {
return getInstance(extension, ApplicationManager.class);
}
public static ApplicationReleaseManager getApplicationReleaseManagerInstance() throws InvalidConfigurationException {
public static ApplicationReleaseManager getApplicationReleaseManagerInstance()
throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.ApplicationReleaseManager);
return getInstance(extension, ApplicationReleaseManager.class);
@ -108,8 +122,9 @@ public class ApplicationManagementUtil {
return constructor.newInstance();
}
} catch (Exception e) {
throw new InvalidConfigurationException("Unable to get instance of extension - " + extension.getName()
+ " , for class - " + extension.getClassName(), e);
throw new InvalidConfigurationException(
"Unable to get instance of extension - " + extension.getName() + " , for class - " + extension
.getClassName(), e);
}
}
}

@ -18,11 +18,11 @@
package org.wso2.carbon.device.application.mgt.core.util;
import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
import java.io.File;
/**
* ApplicationMgtDatabaseCreator is responsible for creating the Application Management related tables.

@ -22,6 +22,9 @@ import org.wso2.carbon.utils.CarbonUtils;
import java.io.File;
/**
* Application Management related constants.
*/
public class Constants {
public static final String APPLICATION_CONFIG_XML_FILE = "application-mgt.xml";

@ -20,9 +20,12 @@ package org.wso2.carbon.device.application.mgt.core.util;
import java.util.UUID;
/**
* Utility methods used in the Application Management.
*/
public class HelperUtil {
public static String generateApplicationUuid(){
public static String generateApplicationUuid() {
return UUID.randomUUID().toString();
}

@ -24,16 +24,17 @@ import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;
/**
* This utility class handles the JSON manipulation related tasks.
*/
public class JSONUtil {
public static List<String> jsonArrayStringToList(String value) throws JSONException {
JSONArray jsonArray = new JSONArray(value);
List<String> list = new ArrayList<>();
if (jsonArray != null) {
int len = jsonArray.length();
for (int i = 0; i < len; i++) {
list.add(jsonArray.get(i).toString());
}
int len = jsonArray.length();
for (int i = 0; i < len; i++) {
list.add(jsonArray.get(i).toString());
}
return list;
}

Loading…
Cancel
Save