mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding the ApplicationManagement API to return the images with the getApplication request
This commit is contained in:
parent
3c76c78d76
commit
ce986cb118
@ -195,7 +195,12 @@ public interface ApplicationManagementAPI {
|
|||||||
name = "uuid",
|
name = "uuid",
|
||||||
value = "UUID of the application",
|
value = "UUID of the application",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("uuid") String uuid
|
@PathParam("uuid") String uuid,
|
||||||
|
@ApiParam(
|
||||||
|
name = "isWithImages",
|
||||||
|
value = "Whether to return application with images",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("isWithImages") Boolean IsWithImages
|
||||||
);
|
);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
|
|||||||
@ -72,6 +72,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|||||||
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();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (limit == 0) {
|
if (limit == 0) {
|
||||||
limit = DEFAULT_LIMIT;
|
limit = DEFAULT_LIMIT;
|
||||||
@ -82,6 +84,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|||||||
filter.setSearchQuery(searchQuery);
|
filter.setSearchQuery(searchQuery);
|
||||||
|
|
||||||
ApplicationList applications = applicationManager.getApplications(filter);
|
ApplicationList applications = applicationManager.getApplications(filter);
|
||||||
|
|
||||||
|
for (Application application : applications.getApplications()) {
|
||||||
|
ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(application.getUuid(),
|
||||||
|
"icon", 0);
|
||||||
|
application.setIcon(imageArtifact);
|
||||||
|
}
|
||||||
return Response.status(Response.Status.OK).entity(applications).build();
|
return Response.status(Response.Status.OK).entity(applications).build();
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
@ -95,7 +103,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Path("/{uuid}")
|
@Path("/{uuid}")
|
||||||
public Response getApplication(@PathParam("uuid") String uuid) {
|
public Response getApplication(@PathParam("uuid") String uuid, @QueryParam("isWithImages") Boolean isWithImages) {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||||
try {
|
try {
|
||||||
@ -104,8 +112,18 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|||||||
return Response.status(Response.Status.NOT_FOUND)
|
return Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity("Application with UUID " + uuid + " not found").build();
|
.entity("Application with UUID " + uuid + " not found").build();
|
||||||
}
|
}
|
||||||
ImageArtifact icon = applicationStorageManager.getImageArtifact(uuid, "icon", 0);
|
|
||||||
application.setIcon(icon);
|
if (isWithImages != null && isWithImages) {
|
||||||
|
ImageArtifact icon = applicationStorageManager.getImageArtifact(uuid, "icon", 0);
|
||||||
|
ImageArtifact banner = applicationStorageManager.getImageArtifact(uuid, "banner", 0);
|
||||||
|
int screenShotCount = application.getScreenShotCount();
|
||||||
|
for (int count = 1; count < screenShotCount; count++) {
|
||||||
|
ImageArtifact screenShot = applicationStorageManager.getImageArtifact(uuid, "screenshot", count);
|
||||||
|
application.addScreenShot(screenShot);
|
||||||
|
}
|
||||||
|
application.setIcon(icon);
|
||||||
|
application.setBanner(banner);
|
||||||
|
}
|
||||||
return Response.status(Response.Status.OK).entity(application).build();
|
return Response.status(Response.Status.OK).entity(application).build();
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
|||||||
@ -22,6 +22,7 @@ package org.wso2.carbon.device.application.mgt.common;
|
|||||||
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
|
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -72,6 +73,10 @@ public class Application {
|
|||||||
|
|
||||||
private ImageArtifact icon;
|
private ImageArtifact icon;
|
||||||
|
|
||||||
|
private ImageArtifact banner;
|
||||||
|
|
||||||
|
private List<ImageArtifact> screenShots = new ArrayList<>();
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -228,6 +233,14 @@ public class Application {
|
|||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBanner(ImageArtifact banner) {
|
||||||
|
this.banner = banner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addScreenShot(ImageArtifact screenShot) {
|
||||||
|
this.screenShots.add(screenShot);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String app = "UUID : " + uuid + "\tName : " + name + "\tShort Description : "
|
String app = "UUID : " + uuid + "\tName : " + name + "\tShort Description : "
|
||||||
|
|||||||
@ -53,15 +53,6 @@ public class Configuration {
|
|||||||
public void setExtensions(List<Extension> extensions) {
|
public void setExtensions(List<Extension> extensions) {
|
||||||
this.extensions = extensions;
|
this.extensions = extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "Artifacts")
|
|
||||||
public Artifacts getArtifacts() {
|
|
||||||
return artifacts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArtifacts(Artifacts artifacts) {
|
|
||||||
this.artifacts = artifacts;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -80,7 +80,6 @@ public class Extension {
|
|||||||
public enum Name {
|
public enum Name {
|
||||||
ApplicationManager,
|
ApplicationManager,
|
||||||
ApplicationReleaseManager,
|
ApplicationReleaseManager,
|
||||||
ApplicationUploadManager,
|
|
||||||
CategoryManager,
|
CategoryManager,
|
||||||
CommentsManager,
|
CommentsManager,
|
||||||
LifecycleStateManager,
|
LifecycleStateManager,
|
||||||
|
|||||||
@ -54,13 +54,26 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ApplicationStorageManagerImpl implements ApplicationStorageManager {
|
public class ApplicationStorageManagerImpl implements ApplicationStorageManager {
|
||||||
private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class);
|
private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class);
|
||||||
|
private String storagePath;
|
||||||
|
private int screenShotMaxCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ApplicationStorageManager Instance
|
||||||
|
*
|
||||||
|
* @param storagePath Storage Path to save the binary and image files.
|
||||||
|
* @param screenShotMaxCount Maximum Screen-shots count
|
||||||
|
*/
|
||||||
|
public ApplicationStorageManagerImpl(String storagePath, String screenShotMaxCount) {
|
||||||
|
this.storagePath = storagePath;
|
||||||
|
this.screenShotMaxCount = Integer.parseInt(screenShotMaxCount);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uploadImageArtifacts(String applicationUUID, InputStream iconFileStream, InputStream bannerFileStream,
|
public void uploadImageArtifacts(String applicationUUID, InputStream iconFileStream, InputStream bannerFileStream,
|
||||||
List<InputStream> screenShotStreams) throws ApplicationStorageManagementException {
|
List<InputStream> screenShotStreams) throws ApplicationStorageManagementException {
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
Application application = validateApplication(applicationUUID);
|
Application application = validateApplication(applicationUUID);
|
||||||
String artifactDirectoryPath = Constants.artifactPath + application.getId();
|
String artifactDirectoryPath = storagePath + application.getId();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Artifact Directory Path for saving the artifacts related with application " + applicationUUID
|
log.debug("Artifact Directory Path for saving the artifacts related with application " + applicationUUID
|
||||||
+ " is " + artifactDirectoryPath);
|
+ " is " + artifactDirectoryPath);
|
||||||
@ -86,12 +99,29 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
}
|
}
|
||||||
if (screenShotStreams != null) {
|
if (screenShotStreams != null) {
|
||||||
int count = application.getScreenShotCount() + 1;
|
int count = application.getScreenShotCount() + 1;
|
||||||
|
boolean maxCountReached = false;
|
||||||
|
|
||||||
|
if (count > screenShotMaxCount) {
|
||||||
|
log.error("Maximum limit for the screen-shot is " + screenShotMaxCount
|
||||||
|
+ " Cannot upload another screenshot for the application with the UUID " + applicationUUID);
|
||||||
|
maxCountReached = true;
|
||||||
|
}
|
||||||
String screenshotName;
|
String screenshotName;
|
||||||
|
|
||||||
|
if (maxCountReached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (InputStream screenshotStream : screenShotStreams) {
|
for (InputStream screenshotStream : screenShotStreams) {
|
||||||
try {
|
try {
|
||||||
screenshotName = Constants.IMAGE_ARTIFACTS[2] + count;
|
screenshotName = Constants.IMAGE_ARTIFACTS[2] + count;
|
||||||
saveFile(screenshotStream, artifactDirectoryPath + File.separator + screenshotName);
|
saveFile(screenshotStream, artifactDirectoryPath + File.separator + screenshotName);
|
||||||
count++;
|
count++;
|
||||||
|
if (count > screenShotMaxCount) {
|
||||||
|
log.error("Maximum limit for the screen-shot is " + screenShotMaxCount
|
||||||
|
+ " Cannot upload another screenshot for the application with the UUID "
|
||||||
|
+ applicationUUID);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ApplicationStorageManagementException(
|
throw new ApplicationStorageManagementException(
|
||||||
"IO Exception while saving the screens hots for the " + "application " + applicationUUID,
|
"IO Exception while saving the screens hots for the " + "application " + applicationUUID,
|
||||||
@ -127,7 +157,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile)
|
public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile)
|
||||||
throws ApplicationStorageManagementException {
|
throws ApplicationStorageManagementException {
|
||||||
Application application = validateApplication(applicationUUID);
|
Application application = validateApplication(applicationUUID);
|
||||||
String artifactDirectoryPath = Constants.artifactPath + application.getId();
|
String artifactDirectoryPath = storagePath + application.getId();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Artifact Directory Path for saving the application release related artifacts related with "
|
log.debug("Artifact Directory Path for saving the application release related artifacts related with "
|
||||||
+ "application " + applicationUUID + " is " + artifactDirectoryPath);
|
+ "application " + applicationUUID + " is " + artifactDirectoryPath);
|
||||||
@ -150,7 +180,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
|
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
|
||||||
throws ApplicationStorageManagementException {
|
throws ApplicationStorageManagementException {
|
||||||
Application application = validateApplication(applicationUUID);
|
Application application = validateApplication(applicationUUID);
|
||||||
String artifactPath = Constants.artifactPath + application.getId() + File.separator + versionName;
|
String artifactPath = storagePath + application.getId() + File.separator + versionName;
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);
|
log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);
|
||||||
@ -173,7 +203,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
@Override
|
@Override
|
||||||
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException {
|
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException {
|
||||||
Application application = validateApplication(applicationUUID);
|
Application application = validateApplication(applicationUUID);
|
||||||
String artifactDirectoryPath = Constants.artifactPath + application.getId();
|
String artifactDirectoryPath = storagePath + application.getId();
|
||||||
File artifactDirectory = new File(artifactDirectoryPath);
|
File artifactDirectory = new File(artifactDirectoryPath);
|
||||||
|
|
||||||
if (artifactDirectory.exists()) {
|
if (artifactDirectory.exists()) {
|
||||||
@ -185,7 +215,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
public void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
|
public void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
|
||||||
throws ApplicationStorageManagementException {
|
throws ApplicationStorageManagementException {
|
||||||
Application application = validateApplication(applicationUUID);
|
Application application = validateApplication(applicationUUID);
|
||||||
String artifactPath = Constants.artifactPath + application.getId() + File.separator + version;
|
String artifactPath = storagePath + application.getId() + File.separator + version;
|
||||||
File artifact = new File(artifactPath);
|
File artifact = new File(artifactPath);
|
||||||
|
|
||||||
if (artifact.exists()) {
|
if (artifact.exists()) {
|
||||||
@ -215,7 +245,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
ApplicationStorageManagementException {
|
ApplicationStorageManagementException {
|
||||||
Application application = validateApplication(applicationUUID);
|
Application application = validateApplication(applicationUUID);
|
||||||
validateImageArtifactNames(name);
|
validateImageArtifactNames(name);
|
||||||
String imageArtifactPath = Constants.artifactPath + application.getId() + File.separator + name.toLowerCase();
|
String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase();
|
||||||
|
|
||||||
if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) {
|
if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) {
|
||||||
imageArtifactPath += count;
|
imageArtifactPath += count;
|
||||||
|
|||||||
@ -77,8 +77,6 @@ public class ServiceComponent {
|
|||||||
String datasourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName();
|
String datasourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName();
|
||||||
DAOFactory.init(datasourceName);
|
DAOFactory.init(datasourceName);
|
||||||
|
|
||||||
Constants.artifactPath = ConfigurationManager.getInstance().getConfiguration().getArtifacts()
|
|
||||||
.getBinaryLocation();
|
|
||||||
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
|
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
|
||||||
DataHolder.getInstance().setApplicationManager(applicationManager);
|
DataHolder.getInstance().setApplicationManager(applicationManager);
|
||||||
bundleContext.registerService(ApplicationManager.class.getName(), applicationManager, null);
|
bundleContext.registerService(ApplicationManager.class.getName(), applicationManager, null);
|
||||||
|
|||||||
@ -54,10 +54,6 @@ public class Constants {
|
|||||||
public static final String[] LIFE_CYCLES = {"CREATED", "IN REVIEW", "APPROVED", "REJECTED", "PUBLISHED",
|
public static final String[] LIFE_CYCLES = {"CREATED", "IN REVIEW", "APPROVED", "REJECTED", "PUBLISHED",
|
||||||
"UNPUBLISHED", "RETIRED"};
|
"UNPUBLISHED", "RETIRED"};
|
||||||
|
|
||||||
/**
|
|
||||||
* Path to save the Application related artifacts.
|
|
||||||
*/
|
|
||||||
public static String artifactPath = "";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the image artifacts that are saved in the file system.
|
* Name of the image artifacts that are saved in the file system.
|
||||||
|
|||||||
@ -22,12 +22,6 @@
|
|||||||
<DatasourceName>jdbc/APPM_DS</DatasourceName>
|
<DatasourceName>jdbc/APPM_DS</DatasourceName>
|
||||||
|
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<Extension name="ApplicationUploadManager">
|
|
||||||
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationUploadManagerImpl</ClassName>
|
|
||||||
<Parameters>
|
|
||||||
<Parameter name="UploadPath">repository/resources/mobileapps</Parameter>
|
|
||||||
</Parameters>
|
|
||||||
</Extension>
|
|
||||||
<Extension name="ApplicationManager">
|
<Extension name="ApplicationManager">
|
||||||
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl</ClassName>
|
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl</ClassName>
|
||||||
</Extension>
|
</Extension>
|
||||||
@ -57,10 +51,10 @@
|
|||||||
</Extension>
|
</Extension>
|
||||||
<Extension name="ApplicationStorageManager">
|
<Extension name="ApplicationStorageManager">
|
||||||
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationStorageManagerImpl</ClassName>
|
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationStorageManagerImpl</ClassName>
|
||||||
|
<Parameters>
|
||||||
|
<Parameter name="StoragePath">repository/resources/mobileapps</Parameter>
|
||||||
|
<Parameter name="MaxScreenShotCount">6</Parameter>
|
||||||
|
</Parameters>
|
||||||
</Extension>
|
</Extension>
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|
||||||
<Artifacts>
|
|
||||||
<BinaryLocation>repository/resources/mobileapps/</BinaryLocation>
|
|
||||||
</Artifacts>
|
|
||||||
</ApplicationManagementConfiguration>
|
</ApplicationManagementConfiguration>
|
||||||
Loading…
Reference in New Issue
Block a user