mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding icon update
This commit is contained in:
parent
5c23d42de1
commit
f417f7854e
@ -212,15 +212,15 @@ public interface PlatformManagementAPI {
|
||||
})
|
||||
Response addPlatform(
|
||||
@Multipart(value = "Platform", type = "application/json" ) Platform platform,
|
||||
@Multipart(value = "icon", required = true) Attachment iconFile
|
||||
@Multipart(value = "icon", required = false) Attachment iconFile
|
||||
);
|
||||
|
||||
@PUT
|
||||
@Path("/{identifier}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.MULTIPART_FORM_DATA,
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "Update Platform",
|
||||
@ -246,8 +246,11 @@ public interface PlatformManagementAPI {
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response updatePlatform(
|
||||
@Multipart(value = "Platform", type = "application/json" ) Platform platform,
|
||||
@Multipart(value = "icon", required = false) Attachment iconFile,
|
||||
@ApiParam(
|
||||
name = "platform",
|
||||
value = "The payload of the platform",
|
||||
required = true)
|
||||
Platform platform,
|
||||
@ApiParam(
|
||||
name = "identifier",
|
||||
required = true)
|
||||
@ -372,4 +375,44 @@ public interface PlatformManagementAPI {
|
||||
required = true)
|
||||
@PathParam("name") @Size(min = 3) String name
|
||||
);
|
||||
|
||||
@POST
|
||||
@Path("/{identifier}/icon")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.MULTIPART_FORM_DATA,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Update Platform icon",
|
||||
notes = "This will update the platform icon",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully updated the platform icon"),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request parameters passed."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while updating the platform icon.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response updatePlatformIcon(
|
||||
@ApiParam(
|
||||
name = "identifier",
|
||||
required = true)
|
||||
@PathParam("identifier")
|
||||
@Size(max = 45)
|
||||
String identifier,
|
||||
@Multipart(value = "icon") Attachment iconFile
|
||||
);
|
||||
}
|
||||
|
||||
@ -184,27 +184,14 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
@PUT
|
||||
@Path("/{identifier}")
|
||||
@Override
|
||||
public Response updatePlatform(@Multipart("platform") Platform platform, @Multipart("icon") Attachment
|
||||
icon, @PathParam("identifier") @Size(max = 45) String id) {
|
||||
public Response updatePlatform(Platform platform, @PathParam("identifier") @Size(max = 45) String id) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
APIUtil.getPlatformManager().update(tenantId, id, platform);
|
||||
if (icon != null) {
|
||||
InputStream iconFileStream = icon.getDataHandler().getInputStream();
|
||||
APIUtil.getPlatformStorageManager().uploadIcon(platform.getIdentifier(), iconFileStream);
|
||||
}
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error while updating the platform - " + id + " for tenant domain - " + tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (IOException e) {
|
||||
log.error("IO Exception while trying to update the platform icon for the platform : " + platform
|
||||
.getIdentifier(), e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (ResourceManagementException e) {
|
||||
log.error("Storage Exception while trying to update the platform icon for the platform : " + platform
|
||||
.getIdentifier(), e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,4 +252,28 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{identifier}/icon")
|
||||
@Override
|
||||
public Response updatePlatformIcon(@PathParam("identifier") String identifier, @Multipart("icon") Attachment
|
||||
icon) {
|
||||
try {
|
||||
if (icon != null) {
|
||||
InputStream iconFileStream = icon.getDataHandler().getInputStream();
|
||||
APIUtil.getPlatformStorageManager().uploadIcon(identifier, iconFileStream);
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Icon file is successfully updated for the platform :" + identifier).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("Icon file is not provided to update")
|
||||
.build();
|
||||
}
|
||||
} catch (ResourceManagementException e) {
|
||||
log.error("Resource Management exception while trying to update the icon for the platform " + identifier);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (IOException e) {
|
||||
log.error("IO exception while trying to update the icon for the platform " + identifier);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user