|
|
@ -69,85 +69,114 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|
|
|
private static final int DEFAULT_LIMIT = 20;
|
|
|
|
private static final int DEFAULT_LIMIT = 20;
|
|
|
|
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
|
|
|
|
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
// @GET
|
|
|
|
@GET
|
|
|
|
// @Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
// public Response getApplications(@QueryParam("offset") int offset, @QueryParam("limit") int limit,
|
|
|
|
public Response getApplications(@QueryParam("offset") int offset, @QueryParam("limit") int limit,
|
|
|
|
// @QueryParam("query") String searchQuery) {
|
|
|
|
@QueryParam("query") String searchQuery) {
|
|
|
|
// ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
// ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
//
|
|
|
|
|
|
|
|
// try {
|
|
|
|
try {
|
|
|
|
// if (limit == 0) {
|
|
|
|
if (limit == 0) {
|
|
|
|
// limit = DEFAULT_LIMIT;
|
|
|
|
limit = DEFAULT_LIMIT;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// Filter filter = new Filter();
|
|
|
|
Filter filter = new Filter();
|
|
|
|
// filter.setOffset(offset);
|
|
|
|
filter.setOffset(offset);
|
|
|
|
// filter.setLimit(limit);
|
|
|
|
filter.setLimit(limit);
|
|
|
|
// filter.setSearchQuery(searchQuery);
|
|
|
|
filter.setSearchQuery(searchQuery);
|
|
|
|
//
|
|
|
|
|
|
|
|
// ApplicationList applications = applicationManager.getApplications(filter);
|
|
|
|
ApplicationList applications = applicationManager.getApplications(filter);
|
|
|
|
//
|
|
|
|
|
|
|
|
// for (Application application : applications.getApplications()) {
|
|
|
|
for (Application application : applications.getApplications()) {
|
|
|
|
// ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(application.getUuid(),
|
|
|
|
// ToDo : use better approach to solve this
|
|
|
|
// Constants.IMAGE_ARTIFACTS[0], 0);
|
|
|
|
String uuId = applicationManager.getUuidOfLatestRelease(application.getId());
|
|
|
|
// application.setIcon(imageArtifact);
|
|
|
|
if (uuId != null){
|
|
|
|
// }
|
|
|
|
application.setUuidOfLatestRelease(uuId);
|
|
|
|
// return Response.status(Response.Status.OK).entity(applications).build();
|
|
|
|
ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0);
|
|
|
|
// } catch (NotFoundException e) {
|
|
|
|
application.setIconOfLatestRelease(imageArtifact);
|
|
|
|
// return Response.status(Response.Status.NOT_FOUND).build();
|
|
|
|
}else{
|
|
|
|
// } catch (ApplicationManagementException e) {
|
|
|
|
// ToDo set default icon
|
|
|
|
// String msg = "Error occurred while getting the application list";
|
|
|
|
}
|
|
|
|
// log.error(msg, e);
|
|
|
|
}
|
|
|
|
// return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(applications).build();
|
|
|
|
// } catch (ApplicationStorageManagementException e) {
|
|
|
|
} catch (NotFoundException e) {
|
|
|
|
// log.error("Error occurred while getting the image artifacts of the application", e);
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).build();
|
|
|
|
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
// }
|
|
|
|
String msg = "Error occurred while getting the application list";
|
|
|
|
// }
|
|
|
|
log.error(msg, e);
|
|
|
|
//
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
// @GET
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
// @Consumes("application/json")
|
|
|
|
log.error("Error occurred while getting the image artifacts of the application", e);
|
|
|
|
// @Path("/{uuid}")
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
// public Response getApplication(@PathParam("uuid") String uuid, @QueryParam("isWithImages") Boolean isWithImages) {
|
|
|
|
}
|
|
|
|
// ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
}
|
|
|
|
// ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
|
|
|
|
// try {
|
|
|
|
@GET
|
|
|
|
// Application application = applicationManager.getApplication(uuid);
|
|
|
|
@Consumes("application/json")
|
|
|
|
// if (application == null) {
|
|
|
|
@Path("/{appType}")
|
|
|
|
// return Response.status(Response.Status.NOT_FOUND)
|
|
|
|
public Response getApplication(@PathParam("appType") String appType, @QueryParam("appName") String appName) {
|
|
|
|
// .entity("Application with UUID " + uuid + " not found").build();
|
|
|
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
// }
|
|
|
|
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
//
|
|
|
|
try {
|
|
|
|
// if (isWithImages != null && isWithImages) {
|
|
|
|
Application application = applicationManager.getApplication(appType, appName);
|
|
|
|
// ImageArtifact icon = applicationStorageManager.getImageArtifact(uuid, Constants.IMAGE_ARTIFACTS[0], 0);
|
|
|
|
if (application == null) {
|
|
|
|
// ImageArtifact banner = applicationStorageManager.getImageArtifact(uuid, Constants.IMAGE_ARTIFACTS[1],
|
|
|
|
return Response.status(Response.Status.NOT_FOUND)
|
|
|
|
// 0);
|
|
|
|
.entity("Application with UUID " + appType + " not found").build();
|
|
|
|
// int screenShotCount = application.getScreenShotCount();
|
|
|
|
}
|
|
|
|
// for (int count = 1; count < screenShotCount; count++) {
|
|
|
|
|
|
|
|
// ImageArtifact screenShot = applicationStorageManager.getImageArtifact(uuid, Constants
|
|
|
|
// ToDo : use better approach to solve this
|
|
|
|
// .IMAGE_ARTIFACTS[2], count);
|
|
|
|
String uuId = applicationManager.getUuidOfLatestRelease(application.getId());
|
|
|
|
// application.addScreenShot(screenShot);
|
|
|
|
if (uuId != null){
|
|
|
|
// }
|
|
|
|
application.setUuidOfLatestRelease(uuId);
|
|
|
|
// application.setIcon(icon);
|
|
|
|
ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0);
|
|
|
|
// application.setBanner(banner);
|
|
|
|
application.setIconOfLatestRelease(imageArtifact);
|
|
|
|
// }
|
|
|
|
}else{
|
|
|
|
// return Response.status(Response.Status.OK).entity(application).build();
|
|
|
|
// ToDo set default icon
|
|
|
|
// } catch (NotFoundException e) {
|
|
|
|
}
|
|
|
|
// return Response.status(Response.Status.NOT_FOUND).build();
|
|
|
|
|
|
|
|
// } catch (ApplicationManagementException e) {
|
|
|
|
return Response.status(Response.Status.OK).entity(application).build();
|
|
|
|
// log.error("Error occurred while getting application with the uuid " + uuid, e);
|
|
|
|
} catch (NotFoundException e) {
|
|
|
|
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).build();
|
|
|
|
// } catch (ApplicationStorageManagementException e) {
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
// log.error("Error occurred while getting the image artifacts of the application with the uuid " + uuid, e);
|
|
|
|
log.error("Error occurred while getting application with the uuid " + appType, e);
|
|
|
|
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
// }
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
// }
|
|
|
|
log.error("Error occurred while getting the image artifacts of the application with the uuid " + appType, e);
|
|
|
|
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
|
|
|
public Response createApplication(@Valid Application application) {
|
|
|
|
|
|
|
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Application createdApplication = applicationManager.createApplication(application);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (application != null){
|
|
|
|
|
|
|
|
return Response.status(Response.Status.CREATED).entity(createdApplication).build();
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
String msg = "Given device type is not matched with existing device types";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}catch (DeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting the device type";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}catch (ApplicationManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while creating the application";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ToDo
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Path("/{uuid}/lifecycle")
|
|
|
|
@Path("/{uuid}/lifecycle")
|
|
|
|
public Response changeLifecycleState(@PathParam("uuid") String applicationUUID,
|
|
|
|
public Response changeLifecycleState(@PathParam("uuid") String applicationUUID, @QueryParam("state") String state) {
|
|
|
|
@QueryParam("state") String state) {
|
|
|
|
|
|
|
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
|
|
|
|
|
|
|
|
if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) {
|
|
|
|
if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) {
|
|
|
@ -199,33 +228,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
|
|
|
public Response createApplication(@Valid Application application) {
|
|
|
|
|
|
|
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Application createdApplication = applicationManager.createApplication(application);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (application != null){
|
|
|
|
|
|
|
|
return Response.status(Response.Status.CREATED).entity(createdApplication).build();
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
String msg = "Given device type is not matched with existing device types";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}catch (DeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting the device type";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}catch (ApplicationManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while creating the application";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//working on this//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("{appId}/release")
|
|
|
|
@Path("{appId}/release")
|
|
|
@ -258,7 +260,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//working on this//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
@ -393,39 +394,39 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
@Override
|
|
|
|
// @POST
|
|
|
|
@POST
|
|
|
|
// @Path("/release/{uuid}")
|
|
|
|
@Path("/release/{uuid}")
|
|
|
|
// public Response createApplicationRelease(@PathParam("uuid") String applicationUUID,
|
|
|
|
public Response createApplicationRelease(@PathParam("uuid") String applicationUUID,
|
|
|
|
// @Multipart("applicationRelease") ApplicationRelease applicationRelease,
|
|
|
|
@Multipart("applicationRelease") ApplicationRelease applicationRelease,
|
|
|
|
// @Multipart("binaryFile") Attachment binaryFile) {
|
|
|
|
@Multipart("binaryFile") Attachment binaryFile) {
|
|
|
|
// ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
|
|
|
|
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
|
|
|
|
// ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
// try {
|
|
|
|
try {
|
|
|
|
// applicationRelease = applicationReleaseManager.createRelease(applicationUUID, applicationRelease);
|
|
|
|
applicationRelease = applicationReleaseManager.createRelease(applicationUUID, applicationRelease);
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (binaryFile != null) {
|
|
|
|
if (binaryFile != null) {
|
|
|
|
// applicationStorageManager.uploadReleaseArtifacts(applicationUUID, applicationRelease.getVersion(),
|
|
|
|
applicationStorageManager.uploadReleaseArtifacts(applicationUUID, applicationRelease.getVersion(),
|
|
|
|
// binaryFile.getDataHandler().getInputStream());
|
|
|
|
binaryFile.getDataHandler().getInputStream());
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
|
|
|
|
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
|
|
|
|
// } catch (ApplicationManagementException e) {
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
// log.error("Error while creating an application release for the application with UUID " + applicationUUID,
|
|
|
|
log.error("Error while creating an application release for the application with UUID " + applicationUUID,
|
|
|
|
// e);
|
|
|
|
e);
|
|
|
|
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
// } catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// String errorMessage =
|
|
|
|
String errorMessage =
|
|
|
|
// "Error while uploading binary file for the application release of the application with UUID "
|
|
|
|
"Error while uploading binary file for the application release of the application with UUID "
|
|
|
|
// + applicationUUID;
|
|
|
|
+ applicationUUID;
|
|
|
|
// log.error(errorMessage, e);
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
// return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e),
|
|
|
|
return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e),
|
|
|
|
// Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
// } catch (ResourceManagementException e) {
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
// log.error("Error occurred while uploading the releases artifacts of the application with the uuid "
|
|
|
|
log.error("Error occurred while uploading the releases artifacts of the application with the uuid "
|
|
|
|
// + applicationUUID + " for the release " + applicationRelease.getVersion(), e);
|
|
|
|
+ applicationUUID + " for the release " + applicationRelease.getVersion(), e);
|
|
|
|
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
|