Adding icon update

feature/appm-store/pbac
megala21 7 years ago
parent 5c23d42de1
commit f417f7854e

@ -212,15 +212,15 @@ public interface PlatformManagementAPI {
}) })
Response addPlatform( Response addPlatform(
@Multipart(value = "Platform", type = "application/json" ) Platform platform, @Multipart(value = "Platform", type = "application/json" ) Platform platform,
@Multipart(value = "icon", required = true) Attachment iconFile @Multipart(value = "icon", required = false) Attachment iconFile
); );
@PUT @PUT
@Path("/{identifier}") @Path("/{identifier}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Update Platform", value = "Update Platform",
@ -246,8 +246,11 @@ public interface PlatformManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updatePlatform( Response updatePlatform(
@Multipart(value = "Platform", type = "application/json" ) Platform platform, @ApiParam(
@Multipart(value = "icon", required = false) Attachment iconFile, name = "platform",
value = "The payload of the platform",
required = true)
Platform platform,
@ApiParam( @ApiParam(
name = "identifier", name = "identifier",
required = true) required = true)
@ -372,4 +375,44 @@ public interface PlatformManagementAPI {
required = true) required = true)
@PathParam("name") @Size(min = 3) String name @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 @PUT
@Path("/{identifier}") @Path("/{identifier}")
@Override @Override
public Response updatePlatform(@Multipart("platform") Platform platform, @Multipart("icon") Attachment public Response updatePlatform(Platform platform, @PathParam("identifier") @Size(max = 45) String id) {
icon, @PathParam("identifier") @Size(max = 45) String id) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
APIUtil.getPlatformManager().update(tenantId, id, platform); 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(); return Response.status(Response.Status.OK).build();
} catch (PlatformManagementException e) { } catch (PlatformManagementException e) {
log.error("Error while updating the platform - " + id + " for tenant domain - " + tenantId, e); log.error("Error while updating the platform - " + id + " for tenant domain - " + tenantId, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); 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); 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…
Cancel
Save