Merge branch 'master' into 'master'

Add HEAD API to check the existence of application

See merge request entgra/carbon-device-mgt!504
reporting
Saad Sahibjan 5 years ago
commit 2ab716273f

@ -66,6 +66,17 @@ public interface ApplicationManager {
Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException; throws ApplicationManagementException;
/**
* Check the existence of an application for given application name and the device type.
*
* @param appName Application name
* @param deviceTypeName Device Type name
* @return True if application exists for given application name and the device type, otherwise returns False
* @throws ApplicationManagementException if error occured while checking the application existence for given
* application name and device type or request with invalid device type data.
*/
boolean isExistingAppName(String appName, String deviceTypeName) throws ApplicationManagementException;
/** /**
* Updates an already existing application. * Updates an already existing application.
* *

@ -237,7 +237,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream()); byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
String md5OfApp = StorageManagementUtil.getMD5(new ByteArrayInputStream(content)); String md5OfApp = StorageManagementUtil.getMD5(new ByteArrayInputStream(content));
if (md5OfApp == null) { if (md5OfApp == null) {
@ -302,7 +302,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @throws ApplicationManagementException if error occurred while deleting application release artifacts. * @throws ApplicationManagementException if error occurred while deleting application release artifacts.
*/ */
private void deleteApplicationArtifacts(List<String> directoryPaths, int tenantId) throws ApplicationManagementException { private void deleteApplicationArtifacts(List<String> directoryPaths, int tenantId) throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths, tenantId); applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths, tenantId);
} catch (ApplicationStorageManagementException e) { } catch (ApplicationStorageManagementException e) {
@ -328,7 +328,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease) ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease)
throws ResourceManagementException, ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
applicationReleaseDTO.setUuid(uuid); applicationReleaseDTO.setUuid(uuid);
@ -412,7 +412,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact) ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact)
throws ResourceManagementException, ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
// The application executable artifacts such as apks are uploaded. // The application executable artifacts such as apks are uploaded.
try { try {
@ -505,7 +505,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
*/ */
private ApplicationReleaseDTO addImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, private ApplicationReleaseDTO addImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException { ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
applicationReleaseDTO.setIconName(applicationArtifact.getIconName()); applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName()); applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
@ -542,7 +542,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
*/ */
private ApplicationReleaseDTO updateImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, private ApplicationReleaseDTO updateImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException{ ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException{
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
if (!StringUtils.isEmpty(applicationArtifact.getIconName())) { if (!StringUtils.isEmpty(applicationArtifact.getIconName())) {
applicationStorageManager applicationStorageManager
@ -786,7 +786,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @throws ApplicationManagementException which throws if error occurs while during application management. * @throws ApplicationManagementException which throws if error occurs while during application management.
*/ */
private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementException { private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles();
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
List<String> categories = applicationDTO.getAppCategories(); List<String> categories = applicationDTO.getAppCategories();
@ -1329,7 +1329,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ applicationId); + applicationId);
} }
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationDTO applicationDTO = getApplication(applicationId); ApplicationDTO applicationDTO = getApplication(applicationId);
List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs(); List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs();
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
@ -1445,7 +1445,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
public void deleteApplicationRelease(String releaseUuid) public void deleteApplicationRelease(String releaseUuid)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
@ -1793,6 +1793,45 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override
public boolean isExistingAppName(String appName, String deviceTypeName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = DataHolder.getInstance()
.getDeviceManagementService();
try {
DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName);
if (deviceType == null) {
String msg = "Device type doesn't exist. Hence check the application name existence with valid "
+ "device type name.";
log.error(msg);
throw new BadRequestException(msg);
}
try {
ConnectionManagerUtil.openDBConnection();
if (applicationDAO.isExistingAppName(appName, deviceType.getId(), tenantId)) {
return true;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while getting DB connection to check the existence of application with "
+ "name: " + appName + " and the device type: " + deviceTypeName;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while checking the existence of application with " + "name: " + appName
+ "and the device type: " + deviceTypeName + " in the database";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting the device type data for device type: " + deviceTypeName;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
return false;
}
@Override @Override
public Application updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) public Application updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper)
throws ApplicationManagementException { throws ApplicationManagementException {
@ -2707,7 +2746,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
CustomAppReleaseWrapper customAppReleaseWrapper, ApplicationArtifact applicationArtifact) CustomAppReleaseWrapper customAppReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);

@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
@ -55,7 +56,7 @@ public class AppmDataHandlerImpl implements AppmDataHandler {
@Override public InputStream getArtifactStream(int tenantId, String uuid, String folderName, String artifactName) @Override public InputStream getArtifactStream(int tenantId, String uuid, String folderName, String artifactName)
throws ApplicationManagementException { throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO(); ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
String appReleaseHashValue; String appReleaseHashValue;
try { try {
@ -91,7 +92,7 @@ public class AppmDataHandlerImpl implements AppmDataHandler {
@Override @Override
public InputStream getAgentStream(int tenantId, String deviceType) public InputStream getAgentStream(int tenantId, String deviceType)
throws ApplicationManagementException { throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
InputStream inputStream = applicationStorageManager InputStream inputStream = applicationStorageManager
.getFileStream(deviceType, tenantId); .getFileStream(deviceType, tenantId);

@ -87,12 +87,13 @@ public class APIUtil {
* @return ApplicationStoreManager instance in the current osgi context. * @return ApplicationStoreManager instance in the current osgi context.
*/ */
public static ApplicationStorageManager getApplicationStorageManager() { public static ApplicationStorageManager getApplicationStorageManager() {
try {
if (applicationStorageManager == null) { if (applicationStorageManager == null) {
synchronized (APIUtil.class) { synchronized (DAOUtil.class) {
if (applicationStorageManager == null) { if (applicationStorageManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); applicationStorageManager = ApplicationManagementUtil
applicationStorageManager = (ApplicationStorageManager) ctx .getApplicationStorageManagerInstance();
.getOSGiService(ApplicationStorageManager.class, null);
if (applicationStorageManager == null) { if (applicationStorageManager == null) {
String msg = "ApplicationDTO Storage Manager service has not initialized."; String msg = "ApplicationDTO Storage Manager service has not initialized.";
log.error(msg); log.error(msg);
@ -101,6 +102,11 @@ public class APIUtil {
} }
} }
} }
} catch (Exception e) {
String msg = "Error occurred while getting the application store manager";
log.error(msg);
throw new IllegalStateException(msg);
}
return applicationStorageManager; return applicationStorageManager;
} }

@ -22,7 +22,6 @@ import com.google.gson.reflect.TypeToken;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ExecutionStatus; import org.wso2.carbon.device.application.mgt.common.ExecutionStatus;
import org.wso2.carbon.device.application.mgt.common.SubscriptionType; import org.wso2.carbon.device.application.mgt.common.SubscriptionType;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
@ -31,9 +30,6 @@ import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO; import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ScheduledSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.ScheduledSubscriptionDTO;
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.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
@ -311,80 +307,6 @@ public class DAOUtil {
} }
} }
private static volatile ApplicationManager applicationManager;
private static volatile ApplicationStorageManager applicationStorageManager;
private static volatile SubscriptionManager subscriptionManager;
public static ApplicationManager getApplicationManager() {
if (applicationManager == null) {
synchronized (DAOUtil.class) {
if (applicationManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
applicationManager =
(ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
if (applicationManager == null) {
String msg = "ApplicationDTO Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return applicationManager;
}
/**
* To get the ApplicationDTO Storage Manager from the osgi context.
* @return ApplicationStoreManager instance in the current osgi context.
*/
public static ApplicationStorageManager getApplicationStorageManager() {
try {
if (applicationStorageManager == null) {
synchronized (DAOUtil.class) {
if (applicationStorageManager == null) {
applicationStorageManager = ApplicationManagementUtil
.getApplicationStorageManagerInstance();
if (applicationStorageManager == null) {
String msg = "ApplicationDTO Storage Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
} catch (Exception e) {
String msg = "Error occurred while getting the application store manager";
log.error(msg);
throw new IllegalStateException(msg);
}
return applicationStorageManager;
}
/**
* To get the Subscription Manager from the osgi context.
* @return SubscriptionManager instance in the current osgi context.
*/
public static SubscriptionManager getSubscriptionManager() {
if (subscriptionManager == null) {
synchronized (DAOUtil.class) {
if (subscriptionManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
subscriptionManager =
(SubscriptionManager) ctx.getOSGiService(SubscriptionManager.class, null);
if (subscriptionManager == null) {
String msg = "Subscription Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return subscriptionManager;
}
public static DeviceManagementProviderService getDeviceManagementService() { public static DeviceManagementProviderService getDeviceManagementService() {
// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); // PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
// DeviceManagementProviderService deviceManagementProviderService = // DeviceManagementProviderService deviceManagementProviderService =

@ -53,6 +53,7 @@ import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@ -715,6 +716,51 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "screenshot3") Attachment screenshot3 @Multipart(value = "screenshot3") Attachment screenshot3
); );
@HEAD
@Path("/device-type/{deviceType}/app-name/{appName}")
@ApiOperation(
httpMethod = "HEAD",
value = "Check the application existence",
notes = "This API is responsible to check whether application exist or not for the given device type and "
+ "application name.",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Application exists."),
@ApiResponse(
code = 404,
message = "NOT FOUND. \n Could.t find an application for given device type and application "
+ "name."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Found invalid device type with the request."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while checking the application existence"
+ " for given application name and device type name the application list.",
response = ErrorResponse.class)
})
Response isExistingApplication(
@ApiParam(
name = "deviceType",
value = "Application compatible device type name",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "appName",
value = "Application name",
required = true)
@PathParam("appName") String appName
);
@PUT @PUT
@Path("/ent-app-artifacts/{deviceType}/{appId}/{uuid}") @Path("/ent-app-artifacts/{deviceType}/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)

@ -59,6 +59,7 @@ import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@ -319,22 +320,22 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Ent App // Created new Custom App
Application application = applicationManager.createCustomApp(customAppWrapper, Application application = applicationManager.createCustomApp(customAppWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();
} else { } else {
String msg = "Application creation is failed"; String msg = "Custom app creation is failed";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found incompatible payload with pub custom creating request."; String msg = "Found incompatible payload with custom app creating request.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the application"; String msg = "Error occurred while creating a costom application";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) { } catch (RequestValidatingException e) {
@ -384,6 +385,27 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
@Override
@HEAD
@Path("/device-type/{deviceType}/app-name/{appName}")
public Response isExistingApplication(
@PathParam("deviceType") String deviceType,
@PathParam("appName") String appName ){
try {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
if (applicationManager.isExistingAppName(appName, deviceType)) {
return Response.status(Response.Status.OK).build();
}
return Response.status(Response.Status.NOT_FOUND).build();
} catch (BadRequestException e) {
log.error("Found invalid device type to check application existence.", e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (ApplicationManagementException e) {
log.error("Internal Error occurred while checking the application existence.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@Override @Override
@PUT @PUT
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA})

Loading…
Cancel
Save