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) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) 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 * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * 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 * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -13,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.addons; package org.wso2.carbon.device.application.mgt.addons;

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

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

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

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.addons.jaxrs; package org.wso2.carbon.device.application.mgt.addons.jaxrs;

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.addons.jaxrs; package org.wso2.carbon.device.application.mgt.addons.jaxrs;

@ -81,4 +81,32 @@ public interface ConfigRetrieveAPI {
}) })
Response getUiConfig(); 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.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.api.services.ConfigRetrieveAPI; 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.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.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
@ -46,7 +47,26 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI {
public Response getUiConfig() { public Response getUiConfig() {
AppmDataHandler dataHandler = APIUtil.getDataHandler(); AppmDataHandler dataHandler = APIUtil.getDataHandler();
UIConfiguration uiConfiguration = dataHandler.getUIConfiguration(); 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(); 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, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * 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; package org.wso2.carbon.device.application.mgt.common;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;

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

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

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.common.wrapper; package org.wso2.carbon.device.application.mgt.common.wrapper;

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.common.wrapper; package org.wso2.carbon.device.application.mgt.common.wrapper;

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.common.wrapper; 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.RatingConfiguration;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; 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 java.util.List;
import javax.xml.bind.annotation.XmlElement; 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. * @throws ApplicationManagementDAOException if unable to fetch the ApplicationDTO from the data store.
*/ */
ApplicationDTO getApplicationByRelease(String appReleaseUUID, int tenantId) throws ApplicationManagementDAOException; 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.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; 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.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; 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, void subscribeGroupToApplication(int tenantId, String subscribedBy, List<DeviceGroup> groupList, int appId,
int releaseId) throws ApplicationManagementDAOException; 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> 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 void deleteUnrestrictedRoles(List<String> unrestrictedRoles, int applicationId, int tenantId) throws
VisibilityManagementDAOException; 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.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; 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.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
@ -94,6 +95,31 @@ public class Util {
return applications; 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. * 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())) { if (!StringUtils.isEmpty(filter.getAppReleaseState())) {
sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?"; sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?";
} }
if (deviceTypeId > 0) { if (deviceTypeId != -1) {
sql += " AND AP_APP.DEVICE_TYPE_ID = ?"; sql += " AND AP_APP.DEVICE_TYPE_ID = ?";
} }
@ -1095,4 +1095,41 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Util.cleanupResources(stmt, rs); 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.APP_META_INFO AS RELEASE_META_INFO, "
+ "AR.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + "AR.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AR.RATING AS RELEASE_RATING, " + "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 " + "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.UUID = ? AND AR.TENAT_ID = ?"; + "WHERE AR.UUID = ? AND AR.TENANT_ID = ?";
try { try {
connection = this.getDBConnection(); 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.Log;
import org.apache.commons.logging.LogFactory; 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.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; 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.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; 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.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.Device;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
@ -44,7 +49,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
conn = this.getDBConnection(); conn = this.getDBConnection();
long time = System.currentTimeMillis() / 1000; long time = System.currentTimeMillis() / 1000;
String sql = "INSERT INTO AP_DEVICE_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, " 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); stmt = conn.prepareStatement(sql);
for (Device device : deviceList) { for (Device device : deviceList) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
@ -168,4 +173,50 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
Util.cleanupResources(stmt, null); 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 @Override
public void deleteUnrestrictedRoles(List<String> unrestrictedRoles, int applicationId, int tenantId) throws VisibilityManagementDAOException { public void deleteUnrestrictedRoles(List<String> unrestrictedRoles, int applicationId, int tenantId) throws VisibilityManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.core.exception; 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, public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, InputStream iconFileStream,
InputStream bannerFileStream, List<InputStream> screenShotStreams) InputStream bannerFileStream, List<InputStream> screenShotStreams)
throws ResourceManagementException { throws ResourceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String artifactDirectoryPath; String artifactDirectoryPath;
String iconStoredLocation; String iconStoredLocation;
String bannerStoredLocation; String bannerStoredLocation;
@ -122,10 +121,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} catch (IOException e) { } catch (IOException e) {
throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " + throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " +
"the application " + applicationRelease.getUuid(), e); "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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; 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.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; 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.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.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.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
public class AppmDataHandlerImpl implements AppmDataHandler { public class AppmDataHandlerImpl implements AppmDataHandler {
private UIConfiguration uiConfiguration;
private static final Log log = LogFactory.getLog(AppmDataHandlerImpl.class); private static final Log log = LogFactory.getLog(AppmDataHandlerImpl.class);
private UIConfiguration uiConfiguration;
private LifecycleStateManager lifecycleStateManager;
public AppmDataHandlerImpl(UIConfiguration config) { public AppmDataHandlerImpl(UIConfiguration config) {
this.uiConfiguration = config; this.uiConfiguration = config;
lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
} }
@Override @Override
@ -50,6 +59,11 @@ public class AppmDataHandlerImpl implements AppmDataHandler {
return this.uiConfiguration; return this.uiConfiguration;
} }
@Override
public Map<String, State> getLifecycleConfiguration() throws LifecycleManagementException {
return lifecycleStateManager.getLifecycleConfig();
}
@Override @Override
public InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException { public InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); 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.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.impl.AppmDataHandlerImpl; 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.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.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ndatasource.core.DataSourceService; 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.Log;
import org.apache.commons.logging.LogFactory; 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.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; 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.common.permission.mgt.PermissionManagementException;
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils;
import org.wso2.carbon.device.mgt.core.search.mgt.Constants; 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) { public Set<String> getNextLifecycleStates(String currentLifecycleState) {
return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates(); return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates();

@ -21,7 +21,7 @@ import org.junit.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.device.application.mgt.core.config.Configuration; 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.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; import java.util.List;

@ -1,8 +1,8 @@
package org.wso2.carbon.device.application.mgt.core; 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.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.State; import org.wso2.carbon.device.application.mgt.common.State;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; 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.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; 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.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.List;
import java.util.Set; import java.util.Set;

@ -80,7 +80,7 @@ import javax.ws.rs.core.Response;
name = "Get ApplicationDTO Details", name = "Get ApplicationDTO Details",
description = "Get application details", description = "Get application details",
key = "perm:app:publisher:view", key = "perm:app:publisher:view",
permissions = {"/app-mgt/publisher/application/update"} permissions = {"/app-mgt/publisher/application/view"}
), ),
@Scope( @Scope(
name = "Update an ApplicationDTO", name = "Update an ApplicationDTO",
@ -91,8 +91,7 @@ import javax.ws.rs.core.Response;
} }
) )
@Path("/applications") @Path("/applications")
@Api(value = "ApplicationDTO Management", description = "This API carries all application management related operations " + @Api(value = "ApplicationDTO Management")
"such as get all the applications, add application, etc.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public interface ApplicationManagementPublisherAPI { public interface ApplicationManagementPublisherAPI {
@ -181,6 +180,48 @@ public interface ApplicationManagementPublisherAPI {
@QueryParam("state") String state @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 @PUT
@Path("/{appId}") @Path("/{appId}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -377,7 +418,7 @@ public interface ApplicationManagementPublisherAPI {
@DELETE @DELETE
@Consumes("application/json") @Consumes("application/json")
@Path("/{appid}") @Path("/{appId}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -400,14 +441,21 @@ public interface ApplicationManagementPublisherAPI {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while deleting the application.", 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( Response deleteApplication(
@ApiParam( @ApiParam(
name = "UUID", name = "UUID",
value = "Unique identifier of the ApplicationDTO", value = "Unique identifier of the ApplicationDTO",
required = true) required = true)
@PathParam("appid") int applicationId @PathParam("appId") int applicationId
); );
@PUT @PUT
@ -535,7 +583,7 @@ public interface ApplicationManagementPublisherAPI {
); );
@PUT @PUT
@Path("/{deviceType}/{appId}/{uuid}") @Path("/app-release/{deviceType}/{appType}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation( @ApiOperation(
@ -567,21 +615,56 @@ public interface ApplicationManagementPublisherAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updateApplicationRelease( 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, @PathParam("deviceType") String deviceType,
@ApiParam(name = "appId", value = "Identifier of the ApplicationDTO", required = true) @ApiParam(
@PathParam("appId") int applicationId, name = "appType",
@ApiParam(name = "UUID", value = "Unique identifier of the ApplicationDTO Release", required = true) 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, @PathParam("uuid") String applicationUUID,
@Multipart(value = "applicationRelease", required = false, type = "application/json") ApplicationReleaseDTO applicationRelease, @ApiParam(
@Multipart(value = "binaryFile", required = false) Attachment binaryFile, name = "applicationReleaseWrapper",
@Multipart(value = "icon", required = false) Attachment iconFile, value = "Application release wrapper which is going to update.",
@Multipart(value = "banner", required = false) Attachment bannerFile, required = true)
@ApiParam(name = "screenshot1", value = "Screen Shots of the uploading application", 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, @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, @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); @Multipart(value = "screenshot3") Attachment screenshot3);
@GET @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.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.*; 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.dto.LifecycleStateDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; 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.RequestValidatingException;
@ -85,7 +84,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch(BadRequestException e){ } 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); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}catch (ApplicationManagementException e) { }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 @POST
@Consumes("multipart/mixed") @Consumes("multipart/mixed")
public Response createApplication( public Response createApplication(
@ -162,7 +192,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();
} else { } else {
String msg = "ApplicationDTO creation is failed"; String msg = "Application creation is failed";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -286,8 +316,6 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("binaryFile") Attachment binaryFile) { @Multipart("binaryFile") Attachment binaryFile) {
try { try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
if (!ApplicationType.ENTERPRISE.toString().equals(appType)) { if (!ApplicationType.ENTERPRISE.toString().equals(appType)) {
String msg = "If ApplicationDTO type is " + appType String msg = "If ApplicationDTO type is " + appType
+ ", therefore you don't have application release artifact to update for application release UUID: " + ", 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); log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateBinaryArtifact(binaryFile, appType); applicationManager.validateBinaryArtifact(binaryFile, appType);
applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid, applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid,
constructApplicationArtifact(binaryFile, null, null, null)); constructApplicationArtifact(binaryFile, null, null, null));
@ -341,18 +370,14 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
/*
//todo ----------------------
*/
@Override @Override
@PUT @PUT
@Path("/{deviceType}/{appId}/{uuid}") @Path("/app-release/{deviceType}/{appType}/{uuid}")
public Response updateApplicationRelease( public Response updateApplicationRelease(
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("appId") int applicationId, @PathParam("appType") String appType,
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") ApplicationReleaseDTO applicationRelease, @Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile, @Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile, @Multipart("banner") Attachment bannerFile,
@ -360,50 +385,35 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("screenshot2") Attachment screenshot2, @Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) { @Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
InputStream iconFileStream; List<Attachment> screenshots = new ArrayList<>();
InputStream bannerFileStream;
InputStream binaryFileStram;
List<InputStream> attachments = new ArrayList<>();
List<Attachment> attachmentList = new ArrayList<>();
if (screenshot1 != null){ if (screenshot1 != null){
attachmentList.add(screenshot1); screenshots.add(screenshot1);
} }
if (screenshot2 != null) { if (screenshot2 != null) {
attachmentList.add(screenshot2); screenshots.add(screenshot2);
} }
if (screenshot3 != null) { 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 { try {
binaryFileStram = binaryFile.getDataHandler().getInputStream(); applicationManager.validateBinaryArtifact(binaryFile, appType);
iconFileStream = iconFile.getDataHandler().getInputStream(); applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
bannerFileStream = bannerFile.getDataHandler().getInputStream(); if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper,
for (Attachment screenshot : attachmentList) { constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {
attachments.add(screenshot.getDataHandler().getInputStream()); String msg ="Application release updating is failed. Please contact the administrator. "
} + "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
boolean status = applicationManager log.error(msg);
.updateRelease(applicationId, applicationUUID, deviceType, applicationRelease, binaryFileStram, return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
iconFileStream, bannerFileStream, attachments); }
if (!status){ return Response.status(Response.Status.OK).entity("Application release is successfully updated.").build();
log.error("ApplicationDTO release updating is failed. Please contact the administrator. ApplicationDTO id: " } catch (BadRequestException e) {
+ applicationId + ", ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " String msg =
+ deviceType); "Invalid request to update application release for application release UUID " + applicationUUID;
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;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found application or application release for application id: " + applicationId String msg =
+ " and application release UUID " + applicationUUID; "Couldn't found application or application release for application release UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) { } catch (ForbiddenException e) {
@ -411,29 +421,26 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
+ applicationUUID; + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); 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; String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (IOException e) { } catch (RequestValidatingException e) {
String msg = "Error while updating the release artifacts of the application with UUID " + applicationUUID; String msg = "Error occurred while updating the application release in the file system";
log.error(msg, e); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} }
@DELETE @DELETE
@Path("/{appid}") @Path("/{appId}")
public Response deleteApplication( public Response deleteApplication(@PathParam("appId") int applicationId) {
@PathParam("appid") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
List<String> storedLocations = applicationManager.deleteApplication(applicationId); applicationManager.deleteApplication(applicationId);
applicationStorageManager.deleteAllApplicationReleaseArtifacts(storedLocations); return Response.status(Response.Status.OK)
String responseMsg = "Successfully deleted the application and application releases: " + applicationId; .entity("Successfully deleted the application for application ID: " + applicationId).build();
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = String msg =
"Couldn't found application for application id: " + applicationId + " to delete the application"; "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; String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); 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 @GET
@Path("/lifecycle/{appId}/{uuid}") @Path("/lifecycle/{appId}/{uuid}")
public Response getLifecycleState( 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