Added creating app functionality

feature/appm-store/pbac
Chatura Dilan 7 years ago
parent 352c881c24
commit 2b0ae8c5a4

@ -20,13 +20,15 @@ package org.wso2.carbon.device.application.mgt.api.services.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.*;
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.api.APIUtil;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.Date;
@Produces({"application/json"})
@Consumes({"application/json"})
@ -62,4 +64,27 @@ public class ApplicationManagementAPIImpl {
return Response.status(Response.Status.NOT_FOUND).build();
}
}
@POST
@Consumes("application/json")
@Path("applications")
public Response createApplication(@Valid Application application) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
//TODO : Get username and tenantId
User user = new User("admin", -1234);
application.setUser(user);
try {
application = applicationManager.createApplication(application);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the application";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.OK).entity(application).build();
}
}

@ -30,391 +30,5 @@
<PermissionConfiguration>
<APIVersion></APIVersion>
<!--Permission Tree Name-->
<Permission>
<name>Device Management</name>
<path>/device-mgt</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Admin Permissions -->
<Permission>
<name>Device Management Admin</name>
<path>/device-mgt/admin</path>
<url>/</url>
<method>GET</method>
</Permission>
<Permission>
<name>Devices</name>
<path>/device-mgt/devices</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Device related APIs -->
<Permission>
<name>List devices</name>
<path>/device-mgt/devices/List</path>
<url>/devices</url>
<method>GET</method>
</Permission>
<Permission>
<name>Search devices</name>
<path>/device-mgt/devices/Search</path>
<url>/devices/search-devices</url>
<method>POST</method>
</Permission>
<Permission>
<name>View device</name>
<path>/device-mgt/devices/View</path>
<url>/devices/*/*</url>
<method>GET</method>
</Permission>
<Permission>
<name>View device info</name>
<path>/device-mgt/devices/View</path>
<url>/devices/*/*/info</url>
<method>GET</method>
</Permission>
<Permission>
<name>View device applications</name>
<path>/device-mgt/devices/View-Applications</path>
<url>/devices/*/*/applications</url>
<method>GET</method>
</Permission>
<Permission>
<name>View device effective-policy</name>
<path>/device-mgt/devices/View-Active-Policy</path>
<url>/devices/*/*/effective-policy</url>
<method>GET</method>
</Permission>
<Permission>
<name>View devices feature</name>
<path>/device-mgt/devices/View-Features</path>
<url>/devices/*/*/features</url>
<method>GET</method>
</Permission>
<Permission>
<name>View device operations</name>
<path>/device-mgt/devices/View-Operations</path>
<url>/devices/*/*/operations</url>
<method>GET</method>
</Permission>
<Permission>
<name>View Compliance Data</name>
<path>/device-mgt/devices/View-Compliance-Data</path>
<url>/devices/*/*/compliance-data</url>
<method>GET</method>
</Permission>
<Permission>
<name>List all devices</name>
<path>/device-mgt/devices/Admin-View</path>
<url>/admin/devices</url>
<method>GET</method>
</Permission>
<Permission>
<name>Verify device authorization</name>
<path>/device-mgt/devices</path>
<url>/admin/authorization</url>
<method>POST</method>
</Permission>
<Permission>
<name>View device types</name>
<path>/device-mgt/devices/Admin-DeviceType-View</path>
<url>/admin/device-types</url>
<method>GET</method>
</Permission>
<!-- End of Device related APIs -->
<Permission>
<name>Policies</name>
<path>/device-mgt/policies</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Policy related APIs -->
<Permission>
<name>List policies</name>
<path>/device-mgt/policies/List</path>
<url>/policies</url>
<method>GET</method>
</Permission>
<Permission>
<name>Add Policy</name>
<path>/device-mgt/policies/Add</path>
<url>/policies</url>
<method>POST</method>
</Permission>
<Permission>
<name>Activate policy</name>
<path>/device-mgt/policies/Activate-Policy</path>
<url>/policies/activate-policy</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Deactivate Policy</name>
<path>/device-mgt/policies/Deactivate-Policy</path>
<url>/policies/deactivate-policy</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Remove Policy</name>
<path>/device-mgt/policies/Remove</path>
<url>/policies/remove-policy</url>
<method>POST</method>
</Permission>
<Permission>
<name>View Policy</name>
<path>/device-mgt/policies/View</path>
<url>/policies/*</url>
<method>GET</method>
</Permission>
<Permission>
<name>Update Policy</name>
<path>/device-mgt/policies/Update</path>
<url>/policies/*</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Update Policy</name>
<path>/device-mgt/policies/Update</path>
<url>/policies/apply-changes</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Update Policy</name>
<path>/device-mgt/policies/Change-Priority</path>
<url>/policies/priorities</url>
<method>PUT</method>
</Permission>
<!-- End of Policy related APIs -->
<Permission>
<name>Notifications</name>
<path>/device-mgt/notifications</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Notification related APIs -->
<Permission>
<name>View notifications</name>
<path>/device-mgt/notifications/View</path>
<url>/notifications</url>
<method>GET</method>
</Permission>
<Permission>
<name>Mark checked notifications</name>
<path>/device-mgt/notifications/View</path>
<url>/notifications/*/mark-checked</url>
<method>PUT</method>
</Permission>
<!-- End of Notification related APIs -->
<Permission>
<name>Users</name>
<path>/device-mgt/users</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- User related APIs -->
<Permission>
<name>List users</name>
<path>/device-mgt/users/List</path>
<url>/users</url>
<method>GET</method>
</Permission>
<Permission>
<name>Add user</name>
<path>/device-mgt/users/Add</path>
<url>/users</url>
<method>POST</method>
</Permission>
<Permission>
<name>List users</name>
<path>/device-mgt/users/Search</path>
<url>/users/search/usernames</url>
<method>GET</method>
</Permission>
<Permission>
<name>Remove user</name>
<path>/device-mgt/users/Remove</path>
<url>/users/*</url>
<method>DELETE</method>
</Permission>
<Permission>
<name>View user</name>
<path>/device-mgt/users/View</path>
<url>/users/*</url>
<method>GET</method>
</Permission>
<Permission>
<name>Update user</name>
<path>/device-mgt/users/Update</path>
<url>/users/*</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Update user credentials</name>
<path>/device-mgt/users/Change-Password</path>
<url>/users/*/credentials</url>
<method>PUT</method>
</Permission>
<Permission>
<name>View assigned role</name>
<path>/device-mgt/roles/Assigned-Roles</path>
<url>/users/*/roles</url>
<method>GET</method>
</Permission>
<Permission>
<name>Change any user credentials</name>
<path>/device-mgt/users/Change-Password-Any</path>
<url>/admin/users/*/credentials</url>
<method>POST</method>
</Permission>
<Permission>
<name>Send invitation mail</name>
<path>/device-mgt/users/Send-invitations</path>
<url>/users/send-invitation</url>
<method>POST</method>
</Permission>
<!-- End of User related APIs -->
<Permission>
<name>Roles</name>
<path>/device-mgt/roles</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Role related APIs -->
<Permission>
<name>List roles</name>
<path>/device-mgt/roles/List</path>
<url>/roles</url>
<method>GET</method>
</Permission>
<Permission>
<name>Add role</name>
<path>/device-mgt/roles/Add</path>
<url>/roles</url>
<method>POST</method>
</Permission>
<Permission>
<name>Remove role</name>
<path>/device-mgt/roles/Remove</path>
<url>/roles/*</url>
<method>DELETE</method>
</Permission>
<Permission>
<name>View role</name>
<path>/device-mgt/roles/View</path>
<url>/roles/*</url>
<method>GET</method>
</Permission>
<Permission>
<name>Update role</name>
<path>/device-mgt/roles/Update</path>
<url>/roles/*</url>
<method>PUT</method>
</Permission>
<Permission>
<name>View role permissions</name>
<path>/device-mgt/roles/View-Permission</path>
<url>/roles/*/permissions</url>
<method>GET</method>
</Permission>
<Permission>
<name>Add Users to role</name>
<path>/device-mgt/roles/Add-Users</path>
<url>/roles/*/users</url>
<method>PUT</method>
</Permission>
<!-- End of Role related APIs -->
<Permission>
<name>Configurations</name>
<path>/device-mgt/general-configs</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Configuration related APIs -->
<Permission>
<name>View configuration</name>
<path>/device-mgt/general-configuration/View</path>
<url>/configuration</url>
<method>GET</method>
</Permission>
<Permission>
<name>Update configuration</name>
<path>/device-mgt/general-configuration/Update</path>
<url>/configuration</url>
<method>PUT</method>
</Permission>
<!-- End of Configuration related APIs -->
<Permission>
<name>Activities</name>
<path>/device-mgt/activities</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Activity related APIs -->
<Permission>
<name>View Activities</name>
<path>/device-mgt/devices/owning/view</path>
<url>/activities</url>
<method>GET</method>
</Permission>
<Permission>
<name>View Activity Details</name>
<path>/device-mgt/devices/owning/view</path>
<url>/activities/*</url>
<method>GET</method>
</Permission>
<!-- End of Activity related APIs -->
<Permission>
<name>Applications</name>
<path>/device-mgt/applications</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- Application related APIs -->
<Permission>
<name>Install Applications</name>
<path>/device-mgt/application/Install</path>
<url>/admin/applications/install-application</url>
<method>POST</method>
</Permission>
<Permission>
<name>Uninstall-Applications</name>
<path>/device-mgt/application/Uninstall</path>
<url>/admin/applications/uninstall-application</url>
<method>POST</method>
</Permission>
<!-- End of Application related APIs -->
<!-- End of Admin Permissions -->
<!-- User Permissions -->
<Permission>
<name>Device Management User</name>
<path>/device-mgt/user</path>
<url>/</url>
<method>GET</method>
</Permission>
<Permission>
<name>User Devices</name>
<path>/device-mgt/user/devices</path>
<url>/</url>
<method>GET</method>
</Permission>
<Permission>
<name>User Policies</name>
<path>/device-mgt/user/policies</path>
<url>/</url>
<method>GET</method>
</Permission>
<Permission>
<name>User Notifications</name>
<path>/device-mgt/user/notifications</path>
<url>/</url>
<method>GET</method>
</Permission>
<Permission>
<name>User Operations</name>
<path>/device-mgt/user/operations</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- End of User Permissions -->
<!--End of Permission Tree-->
</PermissionConfiguration>

@ -58,8 +58,6 @@ public class Application {
private Map<String, String> properties;
private String createdBy;
private Date createdAt;
private Date modifiedAt;
@ -72,6 +70,8 @@ public class Application {
private Visibility visibility;
private User user;
public int getId() {
return id;
}
@ -84,7 +84,6 @@ public class Application {
this.releases = releases;
}
public List<Comment> getComments() {
return comments;
}
@ -217,14 +216,6 @@ public class Application {
this.properties = properties;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreatedAt() {
return createdAt;
}
@ -248,4 +239,12 @@ public class Application {
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}

@ -22,7 +22,6 @@ import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
public class Category {
@Exclude
private int id;
private String name;

@ -25,7 +25,7 @@ public class Lifecycle {
private Date lifecycleStateModifiedAt;
private Date getLifecycleStateModifiedBy;
private String getLifecycleStateModifiedBy;
public LifecycleState getLifecycleState() {
return lifecycleState;
@ -43,11 +43,11 @@ public class Lifecycle {
this.lifecycleStateModifiedAt = lifecycleStateModifiedAt;
}
public Date getGetLifecycleStateModifiedBy() {
public String getGetLifecycleStateModifiedBy() {
return getLifecycleStateModifiedBy;
}
public void setGetLifecycleStateModifiedBy(Date getLifecycleStateModifiedBy) {
public void setGetLifecycleStateModifiedBy(String getLifecycleStateModifiedBy) {
this.getLifecycleStateModifiedBy = getLifecycleStateModifiedBy;
}
}

@ -20,17 +20,19 @@ package org.wso2.carbon.device.application.mgt.common;
public class LifecycleState {
private String id;
private int id;
private String name;
private String identifier;
private String description;
public String getId() {
public int getId() {
return id;
}
public void setId(String id) {
public void setId(int id) {
this.id = id;
}
@ -42,6 +44,14 @@ public class LifecycleState {
this.name = name;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getDescription() {
return description;
}

@ -32,7 +32,7 @@ public class Platform {
private String description;
private String code;
private String identifier;
private String iconName;
@ -40,6 +40,8 @@ public class Platform {
private Map<String, String> properties;
private boolean published;
public int getId() {
return id;
}
@ -64,12 +66,12 @@ public class Platform {
this.description = description;
}
public String getCode() {
return code;
public String getIdentifier() {
return identifier;
}
public void setCode(String code) {
this.code = code;
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getIconName() {
@ -95,4 +97,12 @@ public class Platform {
public void setTags(List<String> tags) {
this.tags = tags;
}
public boolean isPublished() {
return published;
}
public void setPublished(boolean published) {
this.published = published;
}
}

@ -0,0 +1,47 @@
/*
* 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;
public class User {
private String userName;
private int tenantId;
public User(String userName, int tenantId) {
this.userName = userName;
this.tenantId = tenantId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getTenantId() {
return tenantId;
}
public void setTenantId(int tenantId) {
this.tenantId = tenantId;
}
}

@ -32,6 +32,9 @@ public abstract class ApplicationManagementException extends Exception {
setMessage(message);
}
public ApplicationManagementException() {
}
@Override
public String getMessage() {
return message;

@ -27,9 +27,9 @@ public interface ApplicationManager{
public Application createApplication(Application application) throws ApplicationManagementException;
public Application editApplication(int applicationId, Application application) throws ApplicationManagementException;
public Application editApplication(int uuid, Application application) throws ApplicationManagementException;
public void deleteApplication(int applicationId) throws ApplicationManagementException;
public void deleteApplication(int uuid) throws ApplicationManagementException;
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException;
}

@ -18,6 +18,11 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
public interface LifecycleStateDAO {
public LifecycleState getLifeCycleStateByIdentifier(String identifier) throws ApplicationManagementDAOException;
}

@ -18,6 +18,11 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
public interface PlatformDAO {
public Platform getPlatformByIdentifier(String identifier) throws ApplicationManagementDAOException;
}

@ -22,13 +22,17 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.H2ApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.MySQLApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.H2LifecycleStateDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.MySQLLifecycleStateDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.H2PlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.MySQLPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import javax.sql.DataSource;
/**
* This class intends to act as the primary entity that hides all DAO instantiation related complexities and logic so
@ -59,4 +63,34 @@ public class DAOFactory {
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
}
public static PlatformDAO getPlatformDAO(){
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
return new H2PlatformDAOImpl();
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
return new MySQLPlatformDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
public static LifecycleStateDAO getLifecycleStateDAO(){
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
return new H2LifecycleStateDAOImpl();
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
return new MySQLLifecycleStateDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
}

@ -25,6 +25,7 @@ import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.core.util.JSONUtil;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -46,13 +47,13 @@ public class Util {
application.setIconName(rs.getString("ICON_NAME"));
application.setBannerName(rs.getString("BANNER_NAME"));
application.setVideoName(rs.getString("VIDEO_NAME"));
application.setScreenshots(jsonArrayStringToList(rs.getString("SCREENSHOTS")));
application.setScreenshots(JSONUtil.jsonArrayStringToList(rs.getString("SCREENSHOTS")));
application.setCreatedAt(rs.getDate("CREATED_AT"));
application.setModifiedAt(rs.getDate("MODIFIED_AT"));
Platform platform = new Platform();
platform.setName(rs.getString("APL_NAME"));
platform.setCode(rs.getString("APL_IDENTIFIER"));
platform.setIdentifier(rs.getString("APL_IDENTIFIER"));
application.setPlatform(platform);
Map<String, String> properties = new HashMap<>();
@ -90,15 +91,5 @@ public class Util {
}
}
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());
}
}
return list;
}
}

@ -0,0 +1,31 @@
/*
* 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.dao.impl;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.Connection;
public abstract class AbstractDAOImpl {
protected Connection getConnection() throws DBConnectionException {
return ConnectionManagerUtil.getConnection();
}
}

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.dao.impl;
package org.wso2.carbon.device.application.mgt.core.dao.impl.application;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -24,38 +24,24 @@ import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Filter;
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.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 java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
public abstract class AbstractApplicationDAOImpl extends AbstractDAOImpl implements ApplicationDAO {
private static final Log log = LogFactory.getLog(AbstractApplicationDAOImpl.class);
@Override
public Application createApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
@Override
public Application editApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
@Override
public void deleteApplication(Application application) throws ApplicationManagementDAOException {
}
private Connection getConnection() throws DBConnectionException {
return ConnectionManagerUtil.getConnection();
}
@Override
public int getApplicationCount(Filter filter) throws ApplicationManagementDAOException {
if(log.isDebugEnabled()){
@ -77,8 +63,7 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
conn = this.getConnection();
sql += "SELECT COUNT(APP.ID) AS APP_COUNT ";
sql += "FROM APPM_APPLICATION AS APP ";
sql += "INNER JOIN APPM_PLATFORM_APPLICATION_MAPPING AS APM ON APP.PLATFORM_APPLICATION_MAPPING_ID = APM.ID ";
sql += "INNER JOIN APPM_PLATFORM AS APL ON APM.PLATFORM_ID = APL.ID ";
sql += "INNER JOIN APPM_PLATFORM AS APL ON APP.PLATFORM_ID = APL.ID ";
sql += "INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON APP.APPLICATION_CATEGORY_ID = CAT.ID ";
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {

@ -28,7 +28,6 @@ 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.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.Connection;
@ -45,6 +44,11 @@ public class H2ApplicationDAOImpl extends AbstractApplicationDAOImpl {
private static final Log log = LogFactory.getLog(H2ApplicationDAOImpl.class);
@Override
public Application createApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementDAOException {
@ -133,7 +137,10 @@ public class H2ApplicationDAOImpl extends AbstractApplicationDAOImpl {
return applicationList;
}
private Connection getConnection() throws DBConnectionException {
return ConnectionManagerUtil.getConnection();
@Override
public Application editApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
}

@ -28,15 +28,14 @@ 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.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.JSONUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* This class holds the generic implementation of ApplicationDAO which can be used to support ANSI db syntax.
@ -48,7 +47,7 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
@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()));
}
@ -75,8 +74,7 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
sql += "SELECT SQL_CALC_FOUND_ROWS APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER," +
" CAT.NAME AS CAT_NAME ";
sql += "FROM APPM_APPLICATION AS APP ";
sql += "INNER JOIN APPM_PLATFORM_APPLICATION_MAPPING AS APM ON APP.PLATFORM_APPLICATION_MAPPING_ID = APM.ID ";
sql += "INNER JOIN APPM_PLATFORM AS APL ON APM.PLATFORM_ID = APL.ID ";
sql += "INNER JOIN APPM_PLATFORM AS APL ON APP.PLATFORM_ID = APL.ID ";
sql += "INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON APP.APPLICATION_CATEGORY_ID = CAT.ID ";
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
@ -139,7 +137,85 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
return applicationList;
}
private Connection getConnection() throws DBConnectionException {
return ConnectionManagerUtil.getConnection();
@Override
public Application editApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
@Override
public Application createApplication(Application application) throws ApplicationManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
try {
conn = this.getConnection();
sql += "INSERT INTO APPM_APPLICATION (UUID, NAME, SHORT_DESCRIPTION, DESCRIPTION, ICON_NAME, BANNER_NAME, " +
"VIDEO_NAME, SCREENSHOTS, CREATED_BY, CREATED_AT, MODIFIED_AT, APPLICATION_CATEGORY_ID, " + "" +
"PLATFORM_ID, TENANT_ID, LIFECYCLE_STATE_ID, LIFECYCLE_STATE_MODIFIED_AT, " +
"LIFECYCLE_STATE_MODIFIED_BY) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, application.getUuid());
stmt.setString(2, application.getName());
stmt.setString(3, application.getShortDescription());
stmt.setString(4, application.getDescription());
stmt.setString(5, application.getIconName());
stmt.setString(6, application.getBannerName());
stmt.setString(7, application.getVideoName());
stmt.setString(8, JSONUtil.listToJsonArrayString(application.getScreenshots()));
stmt.setString(9, application.getUser().getUserName());
stmt.setDate(10, new Date(application.getCreatedAt().getTime()));
stmt.setDate(11, new Date(application.getModifiedAt().getTime()));
stmt.setInt(12, application.getCategory().getId());
stmt.setInt(13, application.getPlatform().getId());
stmt.setInt(14, application.getUser().getTenantId());
stmt.setInt(15, application.getCurrentLifecycle().getLifecycleState().getId());
stmt.setDate(16, new Date(application.getCurrentLifecycle().getLifecycleStateModifiedAt().getTime()));
stmt.setString(17, application.getCurrentLifecycle().getGetLifecycleStateModifiedBy());
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
if (rs.next()) {
application.setId(rs.getInt(1));
}
if (application.getTags() != null && application.getTags().size() > 0) {
sql = "INSERT INTO APPM_APPLICATION_TAG (NAME, APPLICATION_ID) VALUES (?, ?); ";
stmt = conn.prepareStatement(sql);
for (String tag : application.getTags()) {
stmt.setString(1, tag);
stmt.setInt(2, application.getId());
stmt.addBatch();
}
stmt.executeBatch();
}
if (application.getProperties() != null && application.getProperties().size() > 0) {
sql = "INSERT INTO APPM_APPLICATION_PROPERTY (PROP_KEY, PROP_VAL, APPLICATION_ID) VALUES (?, ?, ?); ";
stmt = conn.prepareStatement(sql);
Iterator it = application.getProperties().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> property = (Map.Entry)it.next();
stmt.setString(1, property.getKey());
stmt.setString(2, property.getValue());
stmt.setInt(3, application.getId());
stmt.addBatch();
}
stmt.executeBatch();
}
} 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);
}
return application;
}
}

@ -0,0 +1,26 @@
/*
* 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.dao.impl.lifecyclestate;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
public abstract class AbstractLifecycleStateDAOImpl extends AbstractDAOImpl implements LifecycleStateDAO {
}

@ -0,0 +1,33 @@
/*
* 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.dao.impl.lifecyclestate;
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.core.dao.impl.platform.AbstractPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
public class H2LifecycleStateDAOImpl extends AbstractLifecycleStateDAOImpl {
@Override
public LifecycleState getLifeCycleStateByIdentifier(String identifier) throws ApplicationManagementDAOException {
return null;
}
}

@ -0,0 +1,76 @@
/*
* 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.dao.impl.lifecyclestate;
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.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.AbstractPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MySQLLifecycleStateDAOImpl extends AbstractLifecycleStateDAOImpl {
@Override
public LifecycleState getLifeCycleStateByIdentifier(String identifier) throws ApplicationManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
try {
conn = this.getConnection();
sql += "SELECT * ";
sql += "FROM APPM_LIFECYCLE_STATE ";
sql += "WHERE IDENTIFIER = ? ";
stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier);
rs = stmt.executeQuery();
LifecycleState lifecycleState = null;
if (rs.next()) {
lifecycleState = new LifecycleState();
lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setName(rs.getString("NAME"));
lifecycleState.setIdentifier(rs.getString("IDENTIFIER"));
lifecycleState.setDescription(rs.getString("DESCRIPTION"));
}
return lifecycleState;
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
}

@ -0,0 +1,39 @@
/*
* 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.dao.impl.platform;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
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.util.ConnectionManagerUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public abstract class AbstractPlatformDAOImpl extends AbstractDAOImpl implements PlatformDAO {
}

@ -0,0 +1,31 @@
/*
* 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.dao.impl.platform;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
public class H2PlatformDAOImpl extends AbstractPlatformDAOImpl {
@Override
public Platform getPlatformByIdentifier(String identifier) throws ApplicationManagementDAOException {
return null;
}
}

@ -0,0 +1,74 @@
/*
* 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.dao.impl.platform;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MySQLPlatformDAOImpl extends AbstractPlatformDAOImpl {
@Override
public Platform getPlatformByIdentifier(String identifier) throws ApplicationManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
try {
conn = this.getConnection();
sql += "SELECT * ";
sql += "FROM APPM_PLATFORM ";
sql += "WHERE IDENTIFIER = ? ";
stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier);
rs = stmt.executeQuery();
Platform platform = null;
if (rs.next()) {
platform = new Platform();
platform.setId(rs.getInt("ID"));
platform.setName(rs.getString("NAME"));
platform.setIdentifier(rs.getString("IDENTIFIER"));
platform.setPublished(rs.getBoolean("PUBLISHED"));
}
return platform;
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
}

@ -0,0 +1,33 @@
/*
* 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.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
public class NotFoundException extends ApplicationManagementException {
public NotFoundException(String message, Throwable throwable) {
super(message, throwable);
}
public NotFoundException(String message) {
setMessage(message);
}
}

@ -0,0 +1,32 @@
/*
* 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.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
public class ValidationException extends ApplicationManagementException {
public ValidationException(String message, Throwable throwable) {
super(message, throwable);
}
public ValidationException(String message) {
setMessage(message);
}
}

@ -18,29 +18,87 @@
*/
package org.wso2.carbon.device.application.mgt.core.impl;
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.*;
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.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
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.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
import java.util.Date;
public class ApplicationManagerImpl implements ApplicationManager {
public static final String CREATED = "created";
@Override
public Application createApplication(Application application) throws ApplicationManagementException {
return null;
validateApplication(application, false);
try {
ConnectionManagerUtil.openConnection();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
application.setUuid(HelperUtil.generateApplicationUuid());
application.setCreatedAt(new Date());
application.setModifiedAt(new Date());
LifecycleStateDAO lifecycleStateDAO = DAOFactory.getLifecycleStateDAO();
LifecycleState lifecycleState = lifecycleStateDAO.getLifeCycleStateByIdentifier(CREATED);
if (lifecycleState == null) {
throw new NotFoundException("Invalid lifecycle state.");
}
Lifecycle lifecycle = new Lifecycle();
lifecycle.setLifecycleState(lifecycleState);
lifecycle.setLifecycleState(lifecycleState);
lifecycle.setLifecycleStateModifiedAt(new Date());
lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName());
application.setCurrentLifecycle(lifecycle);
PlatformDAO platformDAO = DAOFactory.getPlatformDAO();
Platform platform = platformDAO.getPlatformByIdentifier(application.getPlatform().getIdentifier());
if (platform == null) {
throw new NotFoundException("Invalid platform");
}
application.setPlatform(platform);
return applicationDAO.createApplication(application);
} finally {
ConnectionManagerUtil.closeConnection();
}
}
@Override
public Application editApplication(int applicationId, Application application) throws ApplicationManagementException {
return null;
public Application editApplication(int uuid, Application application) throws ApplicationManagementException {
validateApplication(application, true);
try {
ConnectionManagerUtil.openConnection();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
application.setModifiedAt(new Date());
return applicationDAO.editApplication(application);
} finally {
ConnectionManagerUtil.closeConnection();
}
}
@Override
public void deleteApplication(int applicationId) throws ApplicationManagementException {
public void deleteApplication(int uuid) throws ApplicationManagementException {
}
@ -56,4 +114,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
private void validateApplication(Application application, boolean isEdit) throws ValidationException {
if (application.getName() == null) {
throw new ValidationException("Application name cannot be empty");
}
if (application.getUser() == null || application.getUser().getUserName() == null ||
application.getUser().getTenantId() == 0) {
throw new ValidationException("Username and tenant Id cannot be empty");
}
if (!isEdit) {
if (application.getCategory() == null || application.getCategory().getId() == 0) {
throw new ValidationException("Category id cannot be empty");
}
if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) {
throw new ValidationException("Platform identifier cannot be empty");
}
}
}
}

@ -130,30 +130,33 @@ public class ConnectionManagerUtil {
}
public static void closeConnection() {
TxState txState = currentTxState.get();
if (TxState.CONNECTION_NOT_BORROWED == txState) {
if (log.isDebugEnabled()) {
log.debug("No successful connection appears to have been borrowed to perform the underlying " +
"transaction even though the 'openConnection' method has been called. Therefore, " +
"'closeConnection' method is returning silently");
if(currentTxState != null) {
TxState txState = currentTxState.get();
if (TxState.CONNECTION_NOT_BORROWED == txState) {
if (log.isDebugEnabled()) {
log.debug("No successful connection appears to have been borrowed to perform the underlying " +
"transaction even though the 'openConnection' method has been called. Therefore, " +
"'closeConnection' method is returning silently");
}
currentTxState.remove();
return;
}
currentTxState.remove();
return;
}
Connection conn = currentConnection.get();
if (conn == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally been caused by not properly initiating the transaction via " +
"'beginTransaction'/'openConnection' methods");
}
try {
conn.close();
} catch (SQLException e) {
log.warn("Error occurred while close the connection", e);
Connection conn = currentConnection.get();
if (conn == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally been caused by not properly initiating the transaction via " +
"'beginTransaction'/'openConnection' methods");
}
try {
conn.close();
} catch (SQLException e) {
log.warn("Error occurred while close the connection", e);
}
currentConnection.remove();
currentTxState.remove();
}
currentConnection.remove();
currentTxState.remove();
}

@ -0,0 +1,29 @@
/*
* 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.util;
import java.util.UUID;
public class HelperUtil {
public static String generateApplicationUuid(){
return UUID.randomUUID().toString();
}
}

@ -0,0 +1,50 @@
/*
* 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.util;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;
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());
}
}
return list;
}
public static String listToJsonArrayString(List<String> list) {
JSONArray jsonArray = new JSONArray();
if (list != null) {
for (String listItem : list) {
jsonArray.put(listItem);
}
}
return jsonArray.toString();
}
}
Loading…
Cancel
Save