mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
partial fix on app update apis -2
This commit is contained in:
parent
4e7f1e4047
commit
7dd7dc8d64
@ -76,6 +76,10 @@ public class Application {
|
||||
value = "If unrestricted roles are defined then isRestricted value is true otherwise it is false")
|
||||
private boolean isRestricted;
|
||||
|
||||
@ApiModelProperty(name = "deviceTypeId",
|
||||
value = "Id of the Related device type of the application",
|
||||
example = "1, 2, 3")
|
||||
private int deviceTypeId;
|
||||
@ApiModelProperty(name = "deviceType",
|
||||
value = "Related device type of the application",
|
||||
required = true,
|
||||
@ -180,4 +184,12 @@ public class Application {
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public int getDeviceTypeId() {
|
||||
return deviceTypeId;
|
||||
}
|
||||
|
||||
public void setDeviceTypeId(int deviceTypeId) {
|
||||
this.deviceTypeId = deviceTypeId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,11 @@ import org.wso2.carbon.device.application.mgt.common.Filter;
|
||||
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
|
||||
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
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.mgt.common.DeviceManagementException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -90,10 +94,14 @@ public interface ApplicationManager {
|
||||
* To get Application with the given Id.
|
||||
*
|
||||
* @param id id of the Application
|
||||
* @return the Application identified by the UUID
|
||||
* @param state state of the Application
|
||||
* @param handleConnections Whether it is required to handle DB connections within(true), or if there are
|
||||
* existing connection(false)
|
||||
* @return the Application identified by the ID
|
||||
* @throws ApplicationManagementException Application Management Exception.
|
||||
*/
|
||||
Application getApplicationById(int id) throws ApplicationManagementException;
|
||||
Application getApplicationById(int id, String state, boolean handleConnections) throws
|
||||
ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* To get an application associated with the release.
|
||||
@ -130,6 +138,16 @@ public interface ApplicationManager {
|
||||
*/
|
||||
List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* To get the release of a particular Application.
|
||||
*
|
||||
* @param applicationId ID of the Application.
|
||||
* @param state state of the Application.
|
||||
* @return the List of the Application releases related with the particular Application.
|
||||
* @throws ApplicationManagementException Application Management Exception.
|
||||
*/
|
||||
List<ApplicationRelease> getReleaseInState(int applicationId, String state) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* To get all the releases of a particular Application.
|
||||
*
|
||||
@ -162,24 +180,33 @@ public interface ApplicationManager {
|
||||
Application getApplicationIfAccessible(int applicationId) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Get the application release for given UUID if application release is exists and application id is valid one.
|
||||
*
|
||||
* @param releaseUuid UUID of the Application Release.
|
||||
* @throws ApplicationManagementException Application Management Exception.
|
||||
*/
|
||||
ApplicationRelease getAppReleaseIfExists(int applicationId, String releaseUuid) throws
|
||||
ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* To update with a new release for an Application.
|
||||
* To update release images such as icons, banner and screenshots.
|
||||
*
|
||||
* @param appId ID of the Application
|
||||
* @param applicationRelease ApplicationRelease
|
||||
* @param uuid uuid of the Application
|
||||
* @param iconFileStream icon file of the release
|
||||
* @param bannerFileStream bannerFileStream of the release.
|
||||
* @param attachments screenshot attachments of the release
|
||||
* @return Updated Application Release.
|
||||
* @throws ApplicationManagementException Application Management Exception.
|
||||
*/
|
||||
ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease)
|
||||
throws ApplicationManagementException;
|
||||
ApplicationRelease updateApplicationImageArtifact(int appId, String uuid, InputStream iconFileStream, InputStream
|
||||
bannerFileStream, List<InputStream> attachments)
|
||||
throws ApplicationManagementException, ResourceManagementException;
|
||||
|
||||
|
||||
/**
|
||||
* To update release images.
|
||||
*
|
||||
* @param appId ID of the Application
|
||||
* @param uuid uuid of the Application
|
||||
* @param binaryFile binaryFile of the release.
|
||||
* @return Updated Application Release.
|
||||
* @throws ApplicationManagementException Application Management Exception.
|
||||
*/
|
||||
ApplicationRelease updateApplicationArtifact(int appId, String uuid, InputStream binaryFile)
|
||||
throws ApplicationManagementException, ResourceManagementException, RequestValidatingException, DeviceManagementException;
|
||||
|
||||
|
||||
/**
|
||||
* To verify whether application release is acceptable to update or not.
|
||||
|
||||
@ -52,7 +52,7 @@ public interface ApplicationStorageManager {
|
||||
* @param screenshots Input Streams of screenshots
|
||||
* @throws ResourceManagementException Resource Management Exception.
|
||||
*/
|
||||
ApplicationRelease updateImageArtifacts(ApplicationRelease applicationRelease, InputStream iconFile,
|
||||
void updateImageArtifacts(ApplicationRelease applicationRelease, InputStream iconFile,
|
||||
InputStream bannerFile, List<InputStream> screenshots)
|
||||
throws ResourceManagementException, ApplicationManagementException;
|
||||
|
||||
|
||||
@ -142,15 +142,15 @@ public interface ApplicationManagementAPI {
|
||||
);
|
||||
|
||||
@GET
|
||||
@Path("/{appType}")
|
||||
@Path("/{appId}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get the application of requesting application type",
|
||||
notes = "This will get the application identified by the application type and name, if exists",
|
||||
value = "get the application of requesting application id and state",
|
||||
notes = "This will get the application identified by the application id and state, if exists",
|
||||
tags = "Application Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ -177,7 +177,12 @@ public interface ApplicationManagementAPI {
|
||||
name = "appId",
|
||||
value = "application Id",
|
||||
required = true)
|
||||
@PathParam("appId") int appId
|
||||
@PathParam("appId") int appId,
|
||||
@ApiParam(
|
||||
name = "state",
|
||||
value = "state",
|
||||
defaultValue = "PUBLISHED")
|
||||
@QueryParam("state") String state
|
||||
);
|
||||
|
||||
@PUT
|
||||
@ -323,10 +328,10 @@ public interface ApplicationManagementAPI {
|
||||
@PathParam("appid") int applicationId
|
||||
);
|
||||
|
||||
@POST
|
||||
@PUT
|
||||
@Path("/image-artifacts/{appId}/{uuid}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Consumes("multipart/mixed")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.MULTIPART_FORM_DATA,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
@ -358,19 +363,47 @@ public interface ApplicationManagementAPI {
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response updateApplicationImageArtifacts(
|
||||
@ApiParam(name = "appId", value = "ID of the application", required = true)
|
||||
@ApiParam(
|
||||
name = "appId",
|
||||
value = "ID of the application",
|
||||
required = true)
|
||||
@PathParam("appId") int applicatioId,
|
||||
@ApiParam(name = "uuid", value = "UUID of the application", required = true)
|
||||
@ApiParam(
|
||||
name = "uuid",
|
||||
value = "UUID of the application",
|
||||
required = true)
|
||||
@PathParam("uuid") String applicationUUID,
|
||||
@ApiParam(
|
||||
name = "icon",
|
||||
value = "Icon of the uploading application",
|
||||
required = true)
|
||||
@Multipart(value = "icon") Attachment iconFile,
|
||||
@ApiParam(
|
||||
name = "banner",
|
||||
value = "Banner of the uploading application",
|
||||
required = true)
|
||||
@Multipart(value = "banner") Attachment bannerFile,
|
||||
@Multipart(value = "screenshot") List<Attachment> screenshots
|
||||
@ApiParam(
|
||||
name = "screenshot1",
|
||||
value = "Screen Shots of the uploading application",
|
||||
required = true)
|
||||
@Multipart(value = "screenshot1") Attachment screenshot1,
|
||||
@ApiParam(
|
||||
name = "screenshot2",
|
||||
value = "Screen Shots of the uploading application",
|
||||
required = false)
|
||||
@Multipart(value = "screenshot2") Attachment screenshot2,
|
||||
@ApiParam(
|
||||
name = "screenshot3",
|
||||
value = "Screen Shots of the uploading application",
|
||||
required = false)
|
||||
@Multipart(value = "screenshot3") Attachment screenshot3
|
||||
);
|
||||
|
||||
@PUT
|
||||
@Path("/app-artifacts/{deviceType}/{appType}/{appId}/{uuid}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Consumes("multipart/mixed")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.MULTIPART_FORM_DATA,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
|
||||
@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagemen
|
||||
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.core.exception.NotFoundException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -90,10 +91,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@Consumes("application/json")
|
||||
@Path("/{appId}")
|
||||
public Response getApplication(
|
||||
@PathParam("appId") int appId) {
|
||||
@PathParam("appId") int appId,
|
||||
@QueryParam("state") String state) {
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
try {
|
||||
Application application = applicationManager.getApplicationById(appId);
|
||||
Application application = applicationManager.getApplicationById(appId, state, true);
|
||||
if (application == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity
|
||||
("Application with application id: " + appId + " not found").build();
|
||||
@ -198,22 +200,22 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
|
||||
@Override
|
||||
@PUT
|
||||
@Consumes("multipart/mixed")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/image-artifacts/{appId}/{uuid}")
|
||||
public Response updateApplicationImageArtifacts(
|
||||
@PathParam("appId") int appId,
|
||||
@PathParam("uuid") String applicationUuid,
|
||||
@Multipart("icon") Attachment iconFile,
|
||||
@Multipart("banner") Attachment bannerFile,
|
||||
@Multipart("screenshot") List<Attachment> attachmentList) {
|
||||
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
ApplicationRelease applicationRelease;
|
||||
@Multipart("screenshot1") Attachment screenshot1,
|
||||
@Multipart("screenshot2") Attachment screenshot2,
|
||||
@Multipart("screenshot3") Attachment screenshot3) {
|
||||
|
||||
try {
|
||||
InputStream iconFileStream = null;
|
||||
InputStream bannerFileStream = null;
|
||||
List<InputStream> attachments = new ArrayList<>();
|
||||
List<InputStream> attachments = new ArrayList<>();;
|
||||
|
||||
if (iconFile != null) {
|
||||
iconFileStream = iconFile.getDataHandler().getInputStream();
|
||||
@ -221,29 +223,22 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
if (bannerFile != null) {
|
||||
bannerFileStream = bannerFile.getDataHandler().getInputStream();
|
||||
}
|
||||
if (attachmentList != null && !attachmentList.isEmpty()) {
|
||||
for (Attachment screenshot : attachmentList) {
|
||||
attachments.add(screenshot.getDataHandler().getInputStream());
|
||||
|
||||
attachments.add(screenshot1.getDataHandler().getInputStream());
|
||||
if(screenshot2 != null) {
|
||||
attachments.add(screenshot2.getDataHandler().getInputStream());
|
||||
}
|
||||
if(screenshot3 != null) {
|
||||
attachments.add(screenshot3.getDataHandler().getInputStream());
|
||||
}
|
||||
applicationRelease = applicationManager.getAppReleaseIfExists(appId, applicationUuid);
|
||||
LifecycleState lifecycleState = applicationManager.getLifecycleState(appId, applicationRelease.getUuid());
|
||||
if (AppLifecycleState.PUBLISHED.toString().equals(lifecycleState.getCurrentState()) ||
|
||||
AppLifecycleState.DEPRECATED.toString().equals(lifecycleState.getCurrentState())) {
|
||||
return Response.status(Response.Status.FORBIDDEN).entity("Can't Update the application release in " +
|
||||
"PUBLISHED or DEPRECATED state. Hence please demote the application and update the application " +
|
||||
"release").build();
|
||||
}
|
||||
applicationRelease = applicationStorageManager
|
||||
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
|
||||
applicationManager.updateRelease(appId, applicationRelease);
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Successfully uploaded artifacts for the application " + applicationUuid).build();
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
applicationManager.updateApplicationImageArtifact(appId,
|
||||
applicationUuid, iconFileStream, bannerFileStream, attachments);
|
||||
|
||||
return Response.status(Response.Status.OK).entity("Successfully uploaded artifacts for the application "
|
||||
+ applicationUuid).build();
|
||||
} catch (NotFoundException e) {
|
||||
String msg =
|
||||
"Couldn't found application release details or storage details or lifecycle details. Application id: "
|
||||
+ appId + " App release uuid: " + applicationUuid;
|
||||
log.error(msg, e);
|
||||
log.error(e.getMessage(), e);
|
||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while updating the application.";
|
||||
@ -263,6 +258,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
|
||||
@Override
|
||||
@PUT
|
||||
@Consumes("multipart/mixed")
|
||||
@Path("/app-artifacts/{deviceType}/{appType}/{appId}/{uuid}")
|
||||
public Response updateApplicationArtifact(
|
||||
@PathParam("deviceType") String deviceType,
|
||||
@ -270,9 +266,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@PathParam("appId") int applicationId,
|
||||
@PathParam("uuid") String applicationUuid,
|
||||
@Multipart("binaryFile") Attachment binaryFile) {
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
ApplicationRelease applicationRelease;
|
||||
|
||||
try {
|
||||
|
||||
@ -280,16 +273,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
return APIUtil.getResponse("Uploading artifacts for the application is failed " + applicationUuid,
|
||||
Response.Status.BAD_REQUEST);
|
||||
}
|
||||
applicationRelease = applicationManager.getAppReleaseIfExists(applicationId, applicationUuid);
|
||||
applicationRelease = applicationStorageManager
|
||||
.updateReleaseArtifacts(applicationRelease, appType, deviceType,
|
||||
APIUtil.getApplicationManager().updateApplicationArtifact(applicationId, applicationUuid,
|
||||
binaryFile.getDataHandler().getInputStream());
|
||||
applicationManager.updateRelease(applicationId, applicationRelease);
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Successfully uploaded artifacts for the application release. UUID is " + applicationUuid).build();
|
||||
} catch (IOException e) {
|
||||
String msg =
|
||||
"Error occured while trying to read icon, banner files for the application release" + applicationUuid;
|
||||
"Error occurred while trying to read icon, banner files for the application release" +
|
||||
applicationUuid;
|
||||
log.error(msg);
|
||||
return APIUtil.getResponse(new ApplicationManagementException(msg, e),
|
||||
Response.Status.BAD_REQUEST);
|
||||
@ -305,6 +296,10 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
log.error("Error occured while handling the application artifact updating request. application release UUID: "
|
||||
+ applicationUuid);
|
||||
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Error occurred while updating the image artifacts of the application with the uuid "
|
||||
+ applicationUuid, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,9 +364,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
}
|
||||
}
|
||||
|
||||
applicationRelease = applicationStorageManager
|
||||
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
|
||||
applicationRelease = applicationManager.updateRelease(applicationId, applicationRelease);
|
||||
// applicationRelease = applicationStorageManager
|
||||
// .updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
|
||||
// applicationRelease = applicationManager.updateRelease(applicationId, applicationRelease);
|
||||
|
||||
return Response.status(Response.Status.OK).entity(applicationRelease).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user