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

Improve app manager APIs

See merge request entgra/carbon-device-mgt!83
feature/appm-store/pbac
Dharmakeerthi Lasantha 6 years ago
commit 79d09ecbfd

@ -1,7 +1,6 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at

@ -1,6 +1,6 @@
/* * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
@ -13,7 +13,6 @@
* 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.addons;

@ -1,7 +1,6 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at

@ -1,20 +1,20 @@
package org.wso2.carbon.device.application.mgt.addons;/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* 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.
*
*/
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@ -1,7 +1,6 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at

@ -1,7 +1,6 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +13,6 @@
* 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.addons.jaxrs;

@ -1,7 +1,6 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +13,6 @@
* 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.addons.jaxrs;

@ -81,4 +81,32 @@ public interface ConfigRetrieveAPI {
})
Response getUiConfig();
@GET
@Path("/lifecycle-config")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get application management UI configuration",
notes = "This will get all UI configuration of application management"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully got Lifecycle Config.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. There doesn't have an defined <LifecycleStates> in app management "
+ "configuration file." +
"query."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the lifecycle config.",
response = ErrorResponse.class)
})
Response getLifecycleConfig();
}

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.api.services.ConfigRetrieveAPI;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
@ -46,7 +47,26 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI {
public Response getUiConfig() {
AppmDataHandler dataHandler = APIUtil.getDataHandler();
UIConfiguration uiConfiguration = dataHandler.getUIConfiguration();
if (uiConfiguration == null){
String msg = "UI configuration is not initiated.";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(uiConfiguration).build();
}
@GET
@Override
@Consumes("application/json")
@Path("/lifecycle-config")
public Response getLifecycleConfig() {
AppmDataHandler dataHandler = APIUtil.getDataHandler();
try {
return Response.status(Response.Status.OK).entity(dataHandler.getLifecycleConfiguration()).build();
} catch (LifecycleManagementException e) {
String msg = "Error Occurred while accessing lifecycle manager.";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -1,4 +1,5 @@
package org.wso2.carbon.device.application.mgt.common;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
package org.wso2.carbon.device.application.mgt.common;
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except

@ -1,4 +1,4 @@
package org.wso2.carbon.device.application.mgt.core.lifecycle.config;
package org.wso2.carbon.device.application.mgt.common.config;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;

@ -0,0 +1,68 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.common.dto;
import java.sql.Timestamp;
public class DeviceSubscriptionDTO {
private int id;
private String subscribedBy;
private Timestamp subscribedTimestamp;
private boolean isUnsubscribed;
private String unsubscribedBy;
private Timestamp unsubscribedTimestapm;
private String subscribedFrom;
private int deviceId;
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getSubscribedBy() { return subscribedBy; }
public void setSubscribedBy(String subscribedBy) { this.subscribedBy = subscribedBy; }
public Timestamp getSubscribedTimestamp() { return subscribedTimestamp; }
public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
this.subscribedTimestamp = subscribedTimestamp;
}
public boolean isUnsubscribed() { return isUnsubscribed; }
public void setUnsubscribed(boolean unsubscribed) { isUnsubscribed = unsubscribed; }
public String getUnsubscribedBy() { return unsubscribedBy; }
public void setUnsubscribedBy(String unsubscribedBy) { this.unsubscribedBy = unsubscribedBy; }
public Timestamp getUnsubscribedTimestapm() { return unsubscribedTimestapm; }
public void setUnsubscribedTimestapm(Timestamp unsubscribedTimestapm) {
this.unsubscribedTimestapm = unsubscribedTimestapm;
}
public String getSubscribedFrom() { return subscribedFrom; }
public void setSubscribedFrom(String subscribedFrom) { this.subscribedFrom = subscribedFrom; }
public int getDeviceId() { return deviceId; }
public void setDeviceId(int deviceId) { this.deviceId = deviceId; }
}

@ -33,7 +33,6 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseW
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
import java.io.InputStream;
import java.util.List;
/**
@ -68,7 +67,7 @@ public interface ApplicationManager {
* @param applicationId ID for tha application
* @throws ApplicationManagementException ApplicationDTO Management Exception
*/
List<String> deleteApplication(int applicationId) throws ApplicationManagementException;
void deleteApplication(int applicationId) throws ApplicationManagementException;
/**
* Delete an application identified by the unique ID.
@ -77,7 +76,7 @@ public interface ApplicationManager {
* @param releaseUuid UUID of tha application release
* @throws ApplicationManagementException ApplicationDTO Management Exception
*/
String deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException;
void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException;
/**
* To get the applications based on the search filter.
@ -89,7 +88,7 @@ public interface ApplicationManager {
ApplicationList getApplications(Filter filter) throws ApplicationManagementException;
/**
* To get the ApplicationDTO for given Id.
* To get the Application for given Id.
*
* @param id id of the ApplicationDTO
* @param state state of the ApplicationDTO
@ -98,6 +97,15 @@ public interface ApplicationManager {
*/
Application getApplicationById(int id, String state) throws ApplicationManagementException;
/**
* To get the Application Release for given uuid.
*
* @param uuid uuid of the ApplicationDTO
* @return the Application Release identified by the UUID
* @throws ApplicationManagementException Application Management Exception.
*/
ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException;
/**
* To get the ApplicationDTO for given application relase UUID.
*
@ -172,19 +180,16 @@ public interface ApplicationManager {
/***
*
* @param applicationId ID of the application
* @param releaseUuid UUID of the application release
* @param deviceType Supported device type of the application
* @param applicationRelease {@link ApplicationReleaseDTO}
* @param binaryFileStram {@link InputStream} of the binary file
* @param iconFileStream {@link InputStream} of the icon
* @param bannerFileStream {@link InputStream} of the banner
* @param attachments {@link List} of {@link InputStream} of attachments
* @param deviceType Device type which is supported for the Application.
* @param applicationType Application Type
* @param releaseUuid UUID of the application release.
* @param applicationReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False
*/
boolean updateRelease(int applicationId, String releaseUuid, String deviceType, ApplicationReleaseDTO applicationRelease,
InputStream binaryFileStram, InputStream iconFileStream, InputStream bannerFileStream,
List<InputStream> attachments) throws ApplicationManagementException;
boolean updateRelease(String deviceType, String applicationType, String releaseUuid,
ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException;
/***
* To validate the application creating request

@ -22,7 +22,6 @@ package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
import java.io.InputStream;

@ -17,10 +17,13 @@
package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.State;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import java.io.InputStream;
import java.util.Map;
public interface AppmDataHandler {
/**
@ -30,5 +33,7 @@ public interface AppmDataHandler {
*/
UIConfiguration getUIConfiguration();
Map<String, State> getLifecycleConfiguration() throws LifecycleManagementException;
InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException;
}

@ -1,7 +1,6 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +13,6 @@
* 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.wrapper;

@ -1,7 +1,6 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +13,6 @@
* 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.wrapper;

@ -1,7 +1,6 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +13,6 @@
* 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.wrapper;

@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.config;
import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;

@ -207,5 +207,7 @@ public interface ApplicationDAO {
* @throws ApplicationManagementDAOException if unable to fetch the ApplicationDTO from the data store.
*/
ApplicationDTO getApplicationByRelease(String appReleaseUUID, int tenantId) throws ApplicationManagementDAOException;
String getApplicationSubTypeByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException;
}

@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
@ -86,4 +87,8 @@ public interface SubscriptionDAO {
*/
void subscribeGroupToApplication(int tenantId, String subscribedBy, List<DeviceGroup> groupList, int appId,
int releaseId) throws ApplicationManagementDAOException;
public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId) throws
ApplicationManagementDAOException;
}

@ -40,6 +40,8 @@ public interface VisibilityDAO {
List<String> getUnrestrictedRoles(int applicationId, int tenantId) throws VisibilityManagementDAOException;
List<String> getUnrestrictedRolesByUUID(String uuid, int tenantId) throws VisibilityManagementDAOException;
void deleteUnrestrictedRoles(List<String> unrestrictedRoles, int applicationId, int tenantId) throws
VisibilityManagementDAOException;

@ -26,6 +26,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
@ -94,6 +95,31 @@ public class Util {
return applications;
}
/**
* To create list of device subscription objects from the result set retrieved from the Database.
*
* @param rs ResultSet
* @return List of device subscriptions that is retrieved from the Database.
* @throws SQLException SQL Exception
* @throws JSONException JSONException.
*/
public static List<DeviceSubscriptionDTO> loadDeviceSubscriptions(ResultSet rs) throws SQLException {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = new ArrayList<>();
while (rs.next()) {
DeviceSubscriptionDTO deviceSubscriptionDTO = new DeviceSubscriptionDTO();
deviceSubscriptionDTO.setId(rs.getInt("ID"));
deviceSubscriptionDTO.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
deviceSubscriptionDTO.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
deviceSubscriptionDTO.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
deviceSubscriptionDTO.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
deviceSubscriptionDTO.setUnsubscribedTimestapm(rs.getTimestamp("UNSUBSCRIBED_AT"));
deviceSubscriptionDTO.setSubscribedFrom(rs.getString("SUBSCRIBED_FROM"));
deviceSubscriptionDTO.setDeviceId(rs.getInt("DEVICE_ID"));
deviceSubscriptionDTOS.add(deviceSubscriptionDTO);
}
return deviceSubscriptionDTOS;
}
/**
* Populates {@link ApplicationReleaseDTO} object with the result obtained from the database.
*

@ -197,7 +197,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (!StringUtils.isEmpty(filter.getAppReleaseState())) {
sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?";
}
if (deviceTypeId > 0) {
if (deviceTypeId != -1) {
sql += " AND AP_APP.DEVICE_TYPE_ID = ?";
}
@ -1095,4 +1095,41 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Util.cleanupResources(stmt, rs);
}
}
@Override
public String getApplicationSubTypeByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
String sql;
try {
conn = this.getDBConnection();
sql = "SELECT AP_APP.SUB_TYPE AS SUB_TYPE "
+ "FROM AP_APP "
+ "WHERE "
+ "AP_APP.ID = (SELECT AP_APP_RELEASE.AP_APP_ID "
+ " FROM AP_APP_RELEASE "
+ " WHERE AP_APP_RELEASE.UUID = ?) "
+ "AND AP_APP.TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
try(ResultSet rs = stmt.executeQuery()){
if (rs.next()){
return rs.getString("SUB_TYPE");
}
return null;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get subscription type of the application "
+ "for given application release uuid. UUID:." + uuid;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while getting application subscribe type for given application release UUID: "
+ uuid + " from database.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -241,9 +241,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "AR.APP_META_INFO AS RELEASE_META_INFO, "
+ "AR.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AR.RATING AS RELEASE_RATING, "
+ "AR.CURRENT_STATE AS RELEASE_CURRENT_STATE, AR.RATED_USERS AS RATED_USER_COUNT "
+ "AR.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
+ "AR.RATED_USERS AS RATED_USER_COUNT "
+ "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.UUID = ? AND AR.TENAT_ID = ?";
+ "WHERE AR.UUID = ? AND AR.TENANT_ID = ?";
try {
connection = this.getDBConnection();

@ -19,16 +19,21 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.subscription;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
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.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
@ -44,7 +49,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
conn = this.getDBConnection();
long time = System.currentTimeMillis() / 1000;
String sql = "INSERT INTO AP_DEVICE_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, "
+ "DM_DEVICE_ID, AP_APP_RELEASE_ID, AP_APP_ID, INSTALL_STATUS) VALUES (?, ?, ?, ?, ?, ?)";
+ "DM_DEVICE_ID, AP_APP_RELEASE_ID, AP_APP_ID, INSTALL_STATUS) VALUES (?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql);
for (Device device : deviceList) {
stmt.setInt(1, tenantId);
@ -168,4 +173,50 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
Util.cleanupResources(stmt, null);
}
}
@Override
public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId) throws
ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ " from the database");
}
Connection conn;
try {
conn = this.getDBConnection();
String sql = "SELECT "
+ "DS.ID AS ID, "
+ "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
+ "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
+ "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+ "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+ "DS.SUBSCRIBED_FROM AS SUBSCRIBED_FROM, "
+ "DS.DM_DEVICE_ID AS DEVICE_ID "
+ "FROM AP_DEVICE_SUBSCRIPTION DS "
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved device subscriptions for application release id "
+ appReleaseId);
}
return Util.loadDeviceSubscriptions(rs);
}
}
} catch (SQLException e) {
String msg =
"Error occurred while getting device subscription data for application ID: " + appReleaseId + ".";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (DBConnectionException e) {
String msg =
"Error occurred while obtaining the DB connection for getting device subscription for applicationID: "
+ appReleaseId + ".";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -104,6 +104,42 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
}
}
@Override
public List<String> getUnrestrictedRolesByUUID(String uuid, int tenantId) throws VisibilityManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get unrestricted roles for UUID: " + uuid);
}
Connection conn;
List<String> unrestrictedRoles = new ArrayList<>();
String sql = "SELECT ROLE FROM AP_UNRESTRICTED_ROLE "
+ "WHERE "
+ "AP_APP_ID = (SELECT AR.AP_APP_ID FROM AP_APP_RELEASE AR WHERE AR.UUID = ? AND AR.TENANT_ID = ? ) "
+ "AND TENANT_ID = ?";
try {
conn = this.getDBConnection();
conn.setAutoCommit(false);
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery();) {
while (rs.next()) {
unrestrictedRoles.add(rs.getString("ROLE"));
}
return unrestrictedRoles;
}
}
} catch (DBConnectionException e) {
throw new VisibilityManagementDAOException(
"Error occurred while obtaining the DB connection when getting unrestricted roles for UUID: "
+ uuid, e);
} catch (SQLException e) {
throw new VisibilityManagementDAOException(
"Error occurred while getting unrestricted roles for UUID: " + uuid, e);
}
}
@Override
public void deleteUnrestrictedRoles(List<String> unrestrictedRoles, int applicationId, int tenantId) throws VisibilityManagementDAOException {
if (log.isDebugEnabled()) {

@ -1,7 +1,6 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +13,6 @@
* 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;

@ -0,0 +1,33 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
/**
* Exception thrown during the ApplicationDTO Management DAO operations.
*/
public class SubscriptionManagementDAOException extends ApplicationManagementException {
public SubscriptionManagementDAOException(String message, Throwable throwable) {
super(message, throwable);
}
public SubscriptionManagementDAOException(String message) {
super(message, new Exception());
}
}

@ -78,7 +78,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, InputStream iconFileStream,
InputStream bannerFileStream, List<InputStream> screenShotStreams)
throws ResourceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String artifactDirectoryPath;
String iconStoredLocation;
String bannerStoredLocation;
@ -122,10 +121,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} catch (IOException e) {
throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " +
"the application " + applicationRelease.getUuid(), e);
} catch (ApplicationStorageManagementException e) {
throw new ApplicationStorageManagementException("ApplicationDTO Management DAO exception while trying to "
+ "update the screen-shot count for the application " + applicationRelease.getUuid() +
" for the tenant id " + tenantId, e);
}
}

@ -20,8 +20,10 @@ package org.wso2.carbon.device.application.mgt.core.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.State;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
@ -30,19 +32,26 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagem
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.io.InputStream;
import java.util.Map;
public class AppmDataHandlerImpl implements AppmDataHandler {
private UIConfiguration uiConfiguration;
private static final Log log = LogFactory.getLog(AppmDataHandlerImpl.class);
private UIConfiguration uiConfiguration;
private LifecycleStateManager lifecycleStateManager;
public AppmDataHandlerImpl(UIConfiguration config) {
this.uiConfiguration = config;
lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
}
@Override
@ -50,6 +59,11 @@ public class AppmDataHandlerImpl implements AppmDataHandler {
return this.uiConfiguration;
}
@Override
public Map<String, State> getLifecycleConfiguration() throws LifecycleManagementException {
return lifecycleStateManager.getLifecycleConfig();
}
@Override
public InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);

@ -32,7 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.impl.AppmDataHandlerImpl;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ndatasource.core.DataSourceService;

@ -19,9 +19,10 @@ package org.wso2.carbon.device.application.mgt.core.lifecycle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.State;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException;
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils;
import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
@ -62,6 +63,15 @@ public class LifecycleStateManager {
}
}
public Map<String, State> getLifecycleConfig() throws LifecycleManagementException {
if (lifecycleStates == null){
String msg = "Lifecycle configuration in not initialized.";
log.error(msg);
throw new LifecycleManagementException(msg);
}
return lifecycleStates;
}
public Set<String> getNextLifecycleStates(String currentLifecycleState) {
return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates();

@ -21,7 +21,7 @@ import org.junit.Assert;
import org.testng.annotations.Test;
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import java.util.List;

@ -1,8 +1,8 @@
package org.wso2.carbon.device.application.mgt.core;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.State;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.State;
import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import java.util.HashMap;
import java.util.List;

@ -7,7 +7,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManageme
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import java.util.List;
import java.util.Set;

@ -80,7 +80,7 @@ import javax.ws.rs.core.Response;
name = "Get ApplicationDTO Details",
description = "Get application details",
key = "perm:app:publisher:view",
permissions = {"/app-mgt/publisher/application/update"}
permissions = {"/app-mgt/publisher/application/view"}
),
@Scope(
name = "Update an ApplicationDTO",
@ -91,8 +91,7 @@ import javax.ws.rs.core.Response;
}
)
@Path("/applications")
@Api(value = "ApplicationDTO Management", description = "This API carries all application management related operations " +
"such as get all the applications, add application, etc.")
@Api(value = "ApplicationDTO Management")
@Produces(MediaType.APPLICATION_JSON)
public interface ApplicationManagementPublisherAPI {
@ -181,6 +180,48 @@ public interface ApplicationManagementPublisherAPI {
@QueryParam("state") String state
);
@GET
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get the application release of requesting application UUID and state",
notes = "This will get the application release identified by the application release uuid and state.",
tags = "ApplicationDTO Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved relevant application release.",
response = ApplicationDTO.class),
@ApiResponse(
code = 403,
message = "Don't have permission to access the application release"),
@ApiResponse(
code = 404,
message = "Application release not found"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting relevant application release.",
response = ErrorResponse.class)
})
Response getApplicationRelease(
@ApiParam(
name = "uuid",
value = "application release uuid",
required = true)
@PathParam("uuid") String uuid
);
@PUT
@Path("/{appId}")
@Produces(MediaType.APPLICATION_JSON)
@ -377,7 +418,7 @@ public interface ApplicationManagementPublisherAPI {
@DELETE
@Consumes("application/json")
@Path("/{appid}")
@Path("/{appId}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
@ -400,14 +441,21 @@ public interface ApplicationManagementPublisherAPI {
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting the application.",
response = ErrorResponse.class)
response = ErrorResponse.class),
@ApiResponse(
code = 403,
message = "Don't have permission to delete the application"),
@ApiResponse(
code = 404,
message = "Application not found"),
})
//todo add new scope and permission
Response deleteApplication(
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO",
required = true)
@PathParam("appid") int applicationId
@PathParam("appId") int applicationId
);
@PUT
@ -535,7 +583,7 @@ public interface ApplicationManagementPublisherAPI {
);
@PUT
@Path("/{deviceType}/{appId}/{uuid}")
@Path("/app-release/{deviceType}/{appType}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
@ -567,21 +615,56 @@ public interface ApplicationManagementPublisherAPI {
response = ErrorResponse.class)
})
Response updateApplicationRelease(
@ApiParam(name = "deviceType", value = "Supported device type of the application", required = true)
@ApiParam(
name = "deviceType",
value = "Supported device type of the application",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(name = "appId", value = "Identifier of the ApplicationDTO", required = true)
@PathParam("appId") int applicationId,
@ApiParam(name = "UUID", value = "Unique identifier of the ApplicationDTO Release", required = true)
@ApiParam(
name = "appType",
value = "Type of the application",
required = true)
@PathParam("appType") String appType,
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO Release",
required = true)
@PathParam("uuid") String applicationUUID,
@Multipart(value = "applicationRelease", required = false, type = "application/json") ApplicationReleaseDTO applicationRelease,
@Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@ApiParam(name = "screenshot1", value = "Screen Shots of the uploading application", required = true)
@ApiParam(
name = "applicationReleaseWrapper",
value = "Application release wrapper which is going to update.",
required = true)
@Multipart(
value = "applicationReleaseWrapper",
type = "application/json")
ApplicationReleaseWrapper applicationReleaseWrapper,
@ApiParam(
name = "binaryFile",
value = "Application installer file.",
required = true)
@Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam(
name = "icon",
value = "Icon file of the application release.",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "banner file of the application release.",
required = true)
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "First screenshot of the uploading application",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(name = "screenshot2", value = "Screen Shots of the uploading application")
@ApiParam(
name = "screenshot2",
value = "Second screenshot 2 of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(name = "screenshot3", value = "Screen Shots of the uploading application")
@ApiParam(
name = "screenshot3",
value = "Third screenshot of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3);
@GET

@ -0,0 +1,121 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api.services.admin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* APIs to handle application management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "ApplicationDTO Management Publisher Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ApplicationManagementPublisherAdminService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt-publisher/v1.0/admin/applications"),
})
}
),
tags = {
@Tag(name = "application_management, device_management", description = "App publisher related Admin APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Delete Application Release",
description = "Delete Application Release",
key = "perm:admin:app:publisher:update",
permissions = {"/app-mgt/publisher/admin/application/update"}
)
}
)
@Path("/admin/applications")
@Api(value = "ApplicationDTO Management")
@Produces(MediaType.APPLICATION_JSON)
public interface ApplicationManagementPublisherAdminAPI {
String SCOPE = "scope";
@DELETE
@Path("/release/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete application release.",
notes = "This will delete application release for given UUID",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete application release.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. There doesn't have an application release for UUID" +
"query."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting application release.",
response = ErrorResponse.class)
}) Response deleteApplicationRelease(
@ApiParam(
name = "appId",
value = "application Id",
required = true)
@PathParam("appId") int applicationId,
@ApiParam(
name = "uuid",
value = "application release UUID",
required = true)
@PathParam("uuid") String releaseUuid);
}

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
@ -85,7 +84,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
return Response.status(Response.Status.OK).entity(applications).build();
} catch(BadRequestException e){
String msg = "Incompatible request payload is found. Please try with valid reuest payload.";
String msg = "Incompatible request payload is found. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}catch (ApplicationManagementException e) {
@ -126,6 +125,37 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
}
@GET
@Consumes("application/json")
@Path("/release/{uuid}")
public Response getApplicationRelease(
@PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationRelease applicationRelease = applicationManager.getApplicationReleaseByUUID(uuid);
if (applicationRelease == null){
String msg = "Application release is in the end state of the application lifecycle flow.";
log.error(msg);
return Response.status(Response.Status.OK).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) {
String msg = "Application Release with UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch(ForbiddenException e){
String msg = "You don't have permission to access the application release. application release UUID: : "
+ uuid;
log.error(msg);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}
catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Consumes("multipart/mixed")
public Response createApplication(
@ -162,7 +192,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
} else {
String msg = "ApplicationDTO creation is failed";
String msg = "Application creation is failed";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -286,8 +316,6 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("binaryFile") Attachment binaryFile) {
try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
if (!ApplicationType.ENTERPRISE.toString().equals(appType)) {
String msg = "If ApplicationDTO type is " + appType
+ ", therefore you don't have application release artifact to update for application release UUID: "
@ -295,6 +323,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateBinaryArtifact(binaryFile, appType);
applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid,
constructApplicationArtifact(binaryFile, null, null, null));
@ -341,18 +370,14 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
}
/*
//todo ----------------------
*/
@Override
@PUT
@Path("/{deviceType}/{appId}/{uuid}")
@Path("/app-release/{deviceType}/{appType}/{uuid}")
public Response updateApplicationRelease(
@PathParam("deviceType") String deviceType,
@PathParam("appId") int applicationId,
@PathParam("appType") String appType,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") ApplicationReleaseDTO applicationRelease,
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile,
@ -360,50 +385,35 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
InputStream iconFileStream;
InputStream bannerFileStream;
InputStream binaryFileStram;
List<InputStream> attachments = new ArrayList<>();
List<Attachment> attachmentList = new ArrayList<>();
List<Attachment> screenshots = new ArrayList<>();
if (screenshot1 != null){
attachmentList.add(screenshot1);
screenshots.add(screenshot1);
}
if (screenshot2 != null) {
attachmentList.add(screenshot2);
screenshots.add(screenshot2);
}
if (screenshot3 != null) {
attachmentList.add(screenshot3);
screenshots.add(screenshot3);
}
if (iconFile == null || bannerFile == null || binaryFile == null || attachmentList.isEmpty()){
String msg = "Invalid data is received for application release updating. application id: " + applicationId
+ " and application release UUID: " + applicationUUID;
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
try {
binaryFileStram = binaryFile.getDataHandler().getInputStream();
iconFileStream = iconFile.getDataHandler().getInputStream();
bannerFileStream = bannerFile.getDataHandler().getInputStream();
for (Attachment screenshot : attachmentList) {
attachments.add(screenshot.getDataHandler().getInputStream());
}
boolean status = applicationManager
.updateRelease(applicationId, applicationUUID, deviceType, applicationRelease, binaryFileStram,
iconFileStream, bannerFileStream, attachments);
if (!status){
log.error("ApplicationDTO release updating is failed. Please contact the administrator. ApplicationDTO id: "
+ applicationId + ", ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: "
+ deviceType);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(applicationRelease).build();
}
return Response.status(Response.Status.OK).entity("ApplicationDTO release is successfully updated.").build();
} catch(BadRequestException e){
String msg = "Invalid request to update application release for application release UUID " + applicationUUID;
applicationManager.validateBinaryArtifact(binaryFile, appType);
applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity("Application release is successfully updated.").build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update application release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = "Couldn't found application or application release for application id: " + applicationId
+ " and application release UUID " + applicationUUID;
String msg =
"Couldn't found application or application release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
@ -411,29 +421,26 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}
catch (ApplicationManagementException e) {
} catch (ApplicationManagementException e) {
String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (IOException e) {
String msg = "Error while updating the release artifacts of the application with UUID " + applicationUUID;
log.error(msg, e);
} catch (RequestValidatingException e) {
String msg = "Error occurred while updating the application release in the file system";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Path("/{appid}")
public Response deleteApplication(
@PathParam("appid") int applicationId) {
@Path("/{appId}")
public Response deleteApplication(@PathParam("appId") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
List<String> storedLocations = applicationManager.deleteApplication(applicationId);
applicationStorageManager.deleteAllApplicationReleaseArtifacts(storedLocations);
String responseMsg = "Successfully deleted the application and application releases: " + applicationId;
return Response.status(Response.Status.OK).entity(responseMsg).build();
applicationManager.deleteApplication(applicationId);
return Response.status(Response.Status.OK)
.entity("Successfully deleted the application for application ID: " + applicationId).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found application for application id: " + applicationId + " to delete the application";
@ -447,47 +454,13 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationStorageManagementException e) {
String msg = "Error occurred while deleting the application storage: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@DELETE
@Path("/{appid}/{uuid}")
public Response deleteApplicationRelease(
@PathParam("appid") int applicationId,
@PathParam("uuid") String releaseUuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
String storedLocation = applicationManager.deleteApplicationRelease(applicationId, releaseUuid);
applicationStorageManager.deleteApplicationReleaseArtifacts(storedLocation);
String responseMsg = "Successfully deleted the application release of: " + applicationId + "";
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (NotFoundException e) {
String msg = "Couldn't found application release which is having application id: " + applicationId
+ " and application release UUID:" + releaseUuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg =
"You don't have require permission to delete the application release which has UUID " + releaseUuid
+ " and application ID " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationStorageManagementException e) {
String msg = "Error occurred while deleting the application storage: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
/*
//todo ----------------------
*/
@GET
@Path("/lifecycle/{appId}/{uuid}")
public Response getLifecycleState(

@ -0,0 +1,104 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.publisher.api.services.impl.admin;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.response.Application;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementPublisherAPI;
import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ApplicationManagementPublisherAdminAPI;
import javax.activation.DataHandler;
import javax.validation.Valid;
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.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Implementation of Application Management related APIs.
*/
@Produces({"application/json"})
@Path("/applications")
public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationManagementPublisherAdminAPI {
private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class);
@DELETE
@Path("/release/{appId}/{uuid}")
public Response deleteApplicationRelease(
@PathParam("appId") int applicationId,
@PathParam("uuid") String releaseUuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteApplicationRelease(applicationId, releaseUuid);
String responseMsg = "Successfully deleted the application release for uuid: " + releaseUuid + "";
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (NotFoundException e) {
String msg = "Couldn't found application release which is having application id: " + applicationId
+ " and application release UUID:" + releaseUuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg =
"You don't have require permission to delete the application release which has UUID " + releaseUuid
+ " and application ID " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}
Loading…
Cancel
Save