Merge branch 'application-mgt' of https://github.com/wso2/carbon-device-mgt into application-mgt

feature/appm-store/pbac
amalhub 7 years ago
commit 90bf818fc6

@ -25,6 +25,7 @@ import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager;
@ -47,6 +48,7 @@ public class APIUtil {
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
private static PlatformStorageManager platformStorageManager;
private static CategoryManager categoryManager;
public static ApplicationManager getApplicationManager() {
if (applicationManager == null) {
@ -171,6 +173,29 @@ public class APIUtil {
return platformStorageManager;
}
/**
* To get the Category Manager from the osgi context.
*
* @return CategoryManager instance in the current osgi context.
*/
public static CategoryManager getCategoryManager() {
if (categoryManager == null) {
synchronized (APIUtil.class) {
if (categoryManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null);
if (categoryManager == null) {
String msg = "Category Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return categoryManager;
}
public static Response getResponse(Exception ex, Response.Status status) {
return getResponse(ex.getMessage(), status);
}

@ -36,6 +36,7 @@ import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.Category;
import java.util.List;
import javax.validation.Valid;
@ -101,8 +102,21 @@ import javax.ws.rs.core.Response;
description = "Delete an application",
key = "perm:application:delete",
permissions = {"/device-mgt/application/delete"}
),
@Scope(
name = "Create an application category",
description = "Create an application category",
key = "perm:application-category:create",
permissions = {"/device-mgt/application/category/create"}
),
@Scope(
name = "Delete an Application category",
description = "Delete an application category",
key = "perm:application-category:delete",
permissions = {"/device-mgt/application/category/delete"}
)
}
)
@Path("/applications")
@ -200,7 +214,7 @@ public interface ApplicationManagementAPI {
name = "isWithImages",
value = "Whether to return application with images",
required = false)
@QueryParam("isWithImages") Boolean IsWithImages
@QueryParam("isWithImages") Boolean isWithImages
);
@PUT
@ -747,4 +761,115 @@ public interface ApplicationManagementAPI {
value = "Whether to make it default or not",
required = false)
@QueryParam("isDefault") boolean isDefault);
@POST
@Path("/category")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create an application category",
notes = "This will create a new category",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application-category:create")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully created a new category.",
response = Category.class),
@ApiResponse(
code = 400,
message = "Bad request. Required parameters are not provided"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while creating application category.",
response = ErrorResponse.class)
})
Response createCategory(
@ApiParam(
name = "category",
value = "The category that need to be created.",
required = true)
@Valid Category category);
@GET
@Path("/category")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get existing application categories",
notes = "This will retrieve the existing categories",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:create")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved existing categories.",
response = List.class),
@ApiResponse(
code = 400,
message = "Bad request. Required parameters are not provided"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application "
+ "categories.",
response = ErrorResponse.class)
})
Response getCategories();
@DELETE
@Path("/category/{name}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete application category with the given name",
notes = "This will delete the application category with the given name",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application-category:delete")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the application with the given name.",
response = Application.class),
@ApiResponse(
code = 400,
message = "Bad request. Required parameters are not provided"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting applcation category.",
response = ErrorResponse.class)
})
Response deleteCategory(
@ApiParam(
name = "Name",
value = "Name of the application category",
required = true)
@PathParam("name") String name);
}

@ -32,7 +32,6 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.Platform;
import javax.validation.constraints.Size;
@ -211,7 +210,7 @@ public interface PlatformManagementAPI {
response = ErrorResponse.class)
})
Response addPlatform(
@Multipart(value = "Platform", type = "application/json" ) Platform platform,
@Multipart(value = "Platform", type = "application/json") Platform platform,
@Multipart(value = "icon", required = false) Attachment iconFile
);
@ -371,7 +370,7 @@ public interface PlatformManagementAPI {
response = ErrorResponse.class)
})
Response getPlatformTags(
@ApiParam(name = "name", value ="The initial part of the name of platform tags that we need to retrieve",
@ApiParam(name = "name", value = "The initial part of the name of platform tags that we need to retrieve",
required = true)
@PathParam("name") @Size(min = 3) String name
);

@ -28,6 +28,7 @@ import org.wso2.carbon.device.application.mgt.api.services.ApplicationManagement
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
@ -216,8 +217,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@POST
@Path("/upload-image-artifacts/{uuid}")
public Response uploadApplicationArtifacts(@PathParam("uuid") String applicationUUID,
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart
("screenshot") List<Attachment> attachmentList) {
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
InputStream iconFileStream;
@ -542,4 +543,51 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override
@POST
@Path("/category")
public Response createCategory(@Valid Category category) {
if (category == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Category is null. cannot create the "
+ "category").build();
}
try {
Category createdCategory = APIUtil.getCategoryManager().createCategory(category);
return Response.status(Response.Status.CREATED).entity(createdCategory).build();
} catch (ApplicationManagementException e) {
log.error("Application Management Exception while trying to create the application category", e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override
@GET
@Path("/category")
public Response getCategories() {
List<Category> categories;
try {
categories = APIUtil.getCategoryManager().getCategories();
return Response.status(Response.Status.OK).entity(categories).build();
} catch (ApplicationManagementException e) {
log.error("Application Management Exception while trying to get application categories", e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override
@DELETE
@Path("/category/{name}")
public Response deleteCategory(@PathParam("name") String name) {
if (name == null || name.isEmpty()) {
return Response.status(Response.Status.BAD_REQUEST).entity("Name cannot be null or empty.").build();
}
try {
APIUtil.getCategoryManager().deleteCategory(name);
return Response.status(Response.Status.OK).entity("Successfully deleted the category.").build();
} catch (ApplicationManagementException e) {
log.error("Application Management Exception while trying to delete category", e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}

@ -21,7 +21,6 @@ package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
import java.awt.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@ -18,11 +18,14 @@
*/
package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
/**
* Represents the category a particular {@link Application} belongs to.
*/
public class Category {
@Exclude
private int id;
private String name;

@ -0,0 +1,30 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.common.exception;
/**
* Exception that will be thrown during Application Category Management.
*/
public class ApplicationCategoryManagementException extends ApplicationManagementException {
public ApplicationCategoryManagementException(String message) {
super(message);
setMessage(message);
}
}

@ -27,46 +27,48 @@ import java.util.List;
* ApplicationReleaseManager is responsible for handling all the operations related with
* {@link org.wso2.carbon.device.application.mgt.common.ApplicationRelease} which involving addition, updating ,
* deletion and viewing.
*
*/
public interface ApplicationReleaseManager {
/**
* To create an application release for an Application.
*
* @param appicationUuid UUID of the Application
* @param appicationUuid UUID of the Application
* @param applicationRelease ApplicatonRelease that need to be be created.
* @return the unique id of the application release, if the application release succeeded else -1
*/
public ApplicationRelease createRelease(String appicationUuid, ApplicationRelease applicationRelease) throws
ApplicationManagementException;
ApplicationRelease createRelease(String appicationUuid, ApplicationRelease applicationRelease)
throws ApplicationManagementException;
/**
* To get the application release of the Application/
*
* @param applicationUuid UUID of the Application.
* @param version Version of the ApplicationRelease that need to be retrieved.
* @param version Version of the ApplicationRelease that need to be retrieved.
* @return ApplicationRelease related with particular Application UUID and version.
* @throws ApplicationManagementException ApplicationManagementException
*/
public ApplicationRelease getRelease(String applicationUuid, String version) throws ApplicationManagementException;
ApplicationRelease getRelease(String applicationUuid, String version) throws ApplicationManagementException;
/**
* To get all the releases of a particular Application.
*
* @param applicationUuid UUID of the Application to get all the releases.
* @return the List of the Application releases related with the particular Application.
* @throws ApplicationManagementException Application Management Exception.
*/
public List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException;
List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException;
/**
* To make a particular application release as the default / not default-one
* @param uuid UUID of the application
* @param version Version of the application
* @param isDefault is default or not.
*
* @param uuid UUID of the application
* @param version Version of the application
* @param isDefault is default or not.
* @param releaseChannel Release channel to make the
* @throws ApplicationManagementException Application Management Exception.
*/
public void changeDefaultRelease(String uuid, String version, boolean isDefault, String releaseChannel)
void changeDefaultRelease(String uuid, String version, boolean isDefault, String releaseChannel)
throws ApplicationManagementException;
/**
@ -77,8 +79,8 @@ public interface ApplicationReleaseManager {
* @return Updated Application Release.
* @throws ApplicationManagementException Application Management Exception.
*/
public ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease) throws
ApplicationManagementException;
ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease)
throws ApplicationManagementException;
/**
* To delete a particular release
@ -87,7 +89,7 @@ public interface ApplicationReleaseManager {
* @param version Version of the ApplicationRelease that need to be deleted.
* @throws ApplicationManagementException Application Management Exception.
*/
public void deleteApplicationRelease(String applicationUuid, String version) throws ApplicationManagementException;
void deleteApplicationRelease(String applicationUuid, String version) throws ApplicationManagementException;
/**
* To delete all the application releases related with the the particular application.
@ -95,5 +97,5 @@ public interface ApplicationReleaseManager {
* @param applicationUuid UUID of the application.
* @throws ApplicationManagementException Application Management Exception.
*/
public void deleteApplicationReleases(String applicationUuid) throws ApplicationManagementException;
void deleteApplicationReleases(String applicationUuid) throws ApplicationManagementException;
}

@ -36,37 +36,40 @@ public interface ApplicationStorageManager {
* @param applicationUUID UUID of the application
* @param iconFile Icon File input stream
* @param bannerFile Banner File input stream
* @throws ApplicationStorageManagementException Application Storage Management Exception.
* @throws ResourceManagementException Resource Management Exception.
*/
public void uploadImageArtifacts(String applicationUUID, InputStream iconFile, InputStream bannerFile,
void uploadImageArtifacts(String applicationUUID, InputStream iconFile, InputStream bannerFile,
List<InputStream> screenshots) throws ResourceManagementException;
/**
* To upload release artifacts for an Application.
*
* @param applicationUUID UUID of the application related with the release.
* @param versionName Name of version of the Applcation Release.
* @param binaryFile Binary File for the release.
* @throws ApplicationStorageManagementException Application Storage Management Exception.
* @param versionName Name of version of the Applcation Release.
* @param binaryFile Binary File for the release.
* @throws ResourceManagementException Resource Management Exception.
*/
public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile)
void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile)
throws ResourceManagementException;
/**
* To get released artifacts for the particular version of the application.
*
* @param applicationUUID UUID of the Application
* @param versionName Version of the release to be retrieved
* @param versionName Version of the release to be retrieved
* @return the artifact related with the Application Release.
* @throws ApplicationStorageManagementException Application Storage Management Exception.
*/
public InputStream getReleasedArtifacts(String applicationUUID, String versionName) throws
ApplicationStorageManagementException;
InputStream getReleasedArtifacts(String applicationUUID, String versionName)
throws ApplicationStorageManagementException;
/**
* To delete all the artifacts related with a particular Application.
*
* @param applicationUUID UUID of the Application.
* @throws ApplicationStorageManagementException Application Storage Management Exception.
*/
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException;
void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException;
/**
* To delete the artifacts related with particular Application Release.
@ -75,16 +78,16 @@ public interface ApplicationStorageManager {
* @param version Version of ApplicationRelease that need to be deleted.
* @throws ApplicationStorageManagementException Application Storage Management Exception.
*/
public void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
throws ApplicationStorageManagementException;
/**
* To delete all release artifacts related with particular Application Release.
*
* @param applicationUUID UUID of the Application.
* @throws ApplicationStorageManagementException Application Storage Management Exception
*/
public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws
ApplicationStorageManagementException;
void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws ApplicationStorageManagementException;
/**
* To get particular image artifact of the application.
@ -95,6 +98,6 @@ public interface ApplicationStorageManager {
* @return the relevant image artifact.
* @throws ApplicationStorageManagementException Application Storage Management Exception.
*/
public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws
ApplicationStorageManagementException;
ImageArtifact getImageArtifact(String applicationUUID, String name, int count)
throws ApplicationStorageManagementException;
}

@ -19,19 +19,46 @@
package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import java.util.List;
/**
* CategoryManager is responsible for handling add, delete, update opertaions related with {@link Category}
*/
public interface CategoryManager {
public Category createCategory(Category application) throws ApplicationManagementException;
/**
* To create an application category.
*
* @param category Category that need to be created.
* @return the created Category.
* @throws ApplicationManagementException Application Management Exception
*/
Category createCategory(Category category) throws ApplicationManagementException;
public Category editCategory(int applicationId, Category category) throws ApplicationManagementException;
/**
* To get all the current categories.
*
* @return list of Application categories.
* @throws ApplicationManagementException Application Management Exception.
*/
List<Category> getCategories() throws ApplicationManagementException;
public void deleteCategory(int applicationId) throws ApplicationManagementException;
/**
* To get the category with the given name.
*
* @param name Name of the category to retrieve.
* @return the category with the given name.
* @throws ApplicationManagementException Application Management Exception.
*/
Category getCategory(String name) throws ApplicationManagementException;
public Category getCategory(Filter filter) throws ApplicationManagementException;
/**
* To delete the category with the given name.
*
* @param name Name of the category to be deleted.
* @throws ApplicationManagementException Application Management Exception.
*/
void deleteCategory(String name) throws ApplicationManagementException;
}

@ -35,7 +35,7 @@ public interface PlatformManager {
* @param tenantId ID of the tenant
* @throws PlatformManagementException Platform Management Exception
*/
public void initialize(int tenantId) throws PlatformManagementException;
void initialize(int tenantId) throws PlatformManagementException;
/**
* To get platforms of the specific tenant.
@ -44,7 +44,7 @@ public interface PlatformManager {
* @return List of platforms
* @throws PlatformManagementException Platform Management Exception
*/
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementException;
List<Platform> getPlatforms(int tenantId) throws PlatformManagementException;
/**
* To get platform with the given platform identifier and tenant ID.
@ -54,7 +54,7 @@ public interface PlatformManager {
* @return the Specific platform with the platform identifier and tenant
* @throws PlatformManagementException Platform Management Exception
*/
public Platform getPlatform(int tenantId, String platformIdentifier) throws PlatformManagementException;
Platform getPlatform(int tenantId, String platformIdentifier) throws PlatformManagementException;
/**
* To register a platform under particular tenant.
@ -63,7 +63,7 @@ public interface PlatformManager {
* @param platform Platform to be registered
* @throws PlatformManagementException Platform Management Exception
*/
public void register(int tenantId, Platform platform) throws PlatformManagementException;
void register(int tenantId, Platform platform) throws PlatformManagementException;
/**
* To update a platform.
@ -73,8 +73,7 @@ public interface PlatformManager {
* @param platform Platform to be updated
* @throws PlatformManagementException Platform Management Exception
*/
public void update(int tenantId, String oldPlatformIdentifier, Platform platform)
throws PlatformManagementException;
void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementException;
/**
* To un-register the platform.
@ -84,8 +83,7 @@ public interface PlatformManager {
* @param isFileBased To indicate whether a file based or not.
* @throws PlatformManagementException Platform Management Exception.
*/
public void unregister(int tenantId, String platformIdentifier, boolean isFileBased)
throws PlatformManagementException;
void unregister(int tenantId, String platformIdentifier, boolean isFileBased) throws PlatformManagementException;
/**
* To add mapping to platform identifiers with the tenant ID.
@ -94,7 +92,7 @@ public interface PlatformManager {
* @param platformIdentifiers Platform Identifiers
* @throws PlatformManagementException Platform Management Exception
*/
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementException;
void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementException;
/**
* To add mapping to a platform for a tenant.
@ -103,7 +101,7 @@ public interface PlatformManager {
* @param platformIdentifier ID of the platform, the mapping should be added.
* @throws PlatformManagementException Platform Management Exception.
*/
public void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException;
void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException;
/**
* To remove a mapping of a platform to a tenant.
@ -112,7 +110,7 @@ public interface PlatformManager {
* @param platformIdentifier ID of the platform.
* @throws PlatformManagementException Platform Management Exception.
*/
public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException;
void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException;
/**
* To update the platform status(ENABLED / DISABLED).
@ -122,7 +120,7 @@ public interface PlatformManager {
* @param status Status to be updated.
* @throws PlatformManagementException Platform Management Exception.
*/
public void updatePlatformStatus(int tenantId, String platformIdentifier, String status)
void updatePlatformStatus(int tenantId, String platformIdentifier, String status)
throws PlatformManagementException;
/**
@ -131,7 +129,7 @@ public interface PlatformManager {
* @param tenantId ID of the tenant.
* @throws PlatformManagementException Platform Management Exception.
*/
public void removePlatforms(int tenantId) throws PlatformManagementException;
void removePlatforms(int tenantId) throws PlatformManagementException;
/**
* To get the platform tags.
@ -140,5 +138,5 @@ public interface PlatformManager {
* @return list of the platform tags that start with the character sequence.
* @throws PlatformManagementException PlatformManagement Exception
*/
public List<String> getPlatformTags(String name) throws PlatformManagementException;
List<String> getPlatformTags(String name) throws PlatformManagementException;
}

@ -33,18 +33,19 @@ public interface PlatformStorageManager {
* To upload image artifacts related with an Application.
*
* @param platformIdentifier Identifier of the platform
* @param iconFile Icon File input stream
* @throws PlatformStorageManagementException Platform Storage Management Exception.
* @param iconFile Icon File input stream
* @throws ResourceManagementException Resource Management Exception.
*/
public void uploadIcon(String platformIdentifier, InputStream iconFile) throws ResourceManagementException;
void uploadIcon(String platformIdentifier, InputStream iconFile) throws ResourceManagementException;
/**
* To get the icon for a particular platform.
*
* @param platformIdentifier Identifier of the platform.
* @return the icon for the given platform.
* @throws PlatformStorageManagementException Platform Storage Management Exception.
*/
public ImageArtifact getIcon(String platformIdentifier) throws PlatformStorageManagementException;
ImageArtifact getIcon(String platformIdentifier) throws PlatformStorageManagementException;
/**
* To delete the icon of a particular platform
@ -52,5 +53,5 @@ public interface PlatformStorageManager {
* @param platformIdentifier Identifier of the platform to which delete icon.
* @throws PlatformStorageManagementException PlatformStorageManagement Exception.
*/
public void deleteIcon(String platformIdentifier) throws PlatformStorageManagementException;
void deleteIcon(String platformIdentifier) throws PlatformStorageManagementException;
}

@ -20,50 +20,141 @@ package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.util.List;
import java.util.Map;
/**
* ApplicationDAO is responsible for handling all the Database related operations related with Application Management.
*/
public interface ApplicationDAO {
/**
* To create an application.
*
* @param application Application that need to be created.
* @return Created Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Application createApplication(Application application) throws ApplicationManagementDAOException;
/**
* To get the applications that satisfy the given criteria.
*
* @param filter Filter criteria.
* @param tenantId Id of the tenant.
* @return Application list
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the application with the given uuid
*
* @param uuid UUID of the application to be retrieved.
* @param tenantId ID of the tenant.
* @param userName Name of the user.
* @return the application
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Application getApplication(String uuid, int tenantId, String userName) throws ApplicationManagementDAOException;
/**
* To get the application id of the application specified by the UUID
*
* @param uuid UUID of the application.
* @param tenantId ID of the tenant.
* @return ID of the Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To edit the given application.
*
* @param application Application that need to be edited.
* @param tenantId Tenant ID of the Application.
* @return Updated Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException;
/**
* To delete the application identified by the UUID
*
* @param uuid UUID of the application.
* @param tenantId ID of tenant which the Application belongs to.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteApplication(String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the application count that satisfies gives search query.
*
* @param filter Application Filter.
* @return count of the applications
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
int getApplicationCount(Filter filter) throws ApplicationManagementDAOException;
void addProperties(Map<String, String> properties) throws ApplicationManagementDAOException;
void editProperties(Map<String, String> properties) throws ApplicationManagementDAOException;
/**
* To delete the properties of a application.
*
* @param applicationId ID of the application to delete the properties.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteProperties(int applicationId) throws ApplicationManagementDAOException;
/**
* To delete the tags of a application.
*
* @param applicationId ID of the application to delete the tags.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteTags(int applicationId) throws ApplicationManagementDAOException;
void addRelease(ApplicationRelease release) throws ApplicationManagementDAOException;
void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId) throws
ApplicationManagementDAOException;
List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId) throws
ApplicationManagementDAOException;
void updateScreenShotCount(String applicationUUID, int tenantId, int count) throws
ApplicationManagementDAOException;
/**
* To change the lifecycle state of the application.
*
* @param applicationUUID UUID of the application.
* @param lifecycleIdentifier New lifecycle state.
* @param username Name of the user.
* @param tenantId ID of the tenant.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId)
throws ApplicationManagementDAOException;
/**
* To get the next possible lifecycle states for the application.
*
* @param applicationUUID UUID of the application.
* @param tenantId ID of the tenant.
* @return Next possible lifecycle states.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId)
throws ApplicationManagementDAOException;
/**
* To update the screen-shot count of a application.
*
* @param applicationUUID UUID of the application.
* @param tenantId ID of the tenant.
* @param count New count of the screen-shots.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void updateScreenShotCount(String applicationUUID, int tenantId, int count)
throws ApplicationManagementDAOException;
/**
* To check whether atleast one application exist under category.
*
* @param categoryName Name of the category.
* @return true if atleast one application exist under the given category, otherwise false.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
boolean isApplicationExist(String categoryName) throws ApplicationManagementDAOException;
}

@ -18,8 +18,47 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.util.List;
/**
* This is responsible for Application Category related DAO operations.
*/
public interface CategoryDAO {
/**
* To add a new category.
*
* @param category Category that need to be added.
* @return Newly added category.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Category addCategory(Category category) throws ApplicationManagementDAOException;
/**
* To get the existing categories.
*
* @return Existing categories.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
List<Category> getCategories() throws ApplicationManagementDAOException;
/**
* To get the category with the given name.
*
* @param name Name of the Application category.
* @return Application Category.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Category getCategory(String name) throws ApplicationManagementDAOException;
/**
* To delete a particular category.
*
* @param name Name of the category that need to be deleted.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteCategory(String name) throws ApplicationManagementDAOException;
}

@ -24,6 +24,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDataba
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.CategoryDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
@ -31,11 +32,12 @@ import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.category.GenericCategoryDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
@ -164,6 +166,23 @@ public class DAOFactory {
throw new IllegalStateException("Database engine has not initialized properly.");
}
/**
* To get the instance of CategoryDAOImplementation of the particular database engine.
* @return {@link org.wso2.carbon.device.application.mgt.core.dao.impl.category.GenericCategoryDAOImpl}
*/
public static CategoryDAO getCategoryDAO() {
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericCategoryDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
/**
* This method initializes the databases by creating the database.
*

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.common.Pagination;
@ -58,7 +57,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug("UUID : " + application.getUuid() + " Name : " + application.getName() + " User name : "
+ application.getUser().getUserName());
}
Connection conn = null;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
@ -114,7 +113,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug(String.format("Filter: limit=%s, offset=%", filter.getLimit(), filter.getOffset()));
}
Connection conn = null;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
@ -384,7 +383,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override
public List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId)
throws ApplicationManagementDAOException {
Connection connection = null;
Connection connection;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
@ -445,6 +444,32 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
@Override
public boolean isApplicationExist(String categoryName) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (SELECT ID FROM "
+ "APPM_APPLICATION_CATEGORY WHERE NAME = ?)";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, categoryName);
rs = stmt.executeQuery();
return rs.next();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to check the " + "applications for teh category "
+ categoryName, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL Exception while trying to get the application related with categories, while executing " + sql,
e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
@ -636,7 +661,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override
public int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection conn = null;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql;
@ -661,21 +686,4 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
return id;
}
@Override
public void addProperties(Map<String, String> properties) throws ApplicationManagementDAOException {
}
@Override
public void editProperties(Map<String, String> properties) throws ApplicationManagementDAOException {
}
@Override
public void addRelease(ApplicationRelease release) throws ApplicationManagementDAOException {
}
}

@ -0,0 +1,151 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.dao.impl.category;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.CategoryDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This is the concrete implementation of {@link CategoryDAO}.
*/
public class GenericCategoryDAOImpl extends AbstractDAOImpl implements CategoryDAO {
@Override
public Category addCategory(Category category) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES (?, ?)";
String[] generatedColumns = { "ID" };
ResultSet rs = null;
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql, generatedColumns);
statement.setString(1, category.getName());
statement.setString(2, category.getDescription());
statement.executeUpdate();
rs = statement.getGeneratedKeys();
if (rs.next()) {
category.setId(rs.getInt(1));
}
return category;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection while trying to update the categroy " + category.getName(), e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e);
} finally {
Util.cleanupResources(statement, rs);
}
}
@Override
public List<Category> getCategories() throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY";
List<Category> categories = new ArrayList<>();
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Category category = new Category();
category.setId(rs.getInt("ID"));
category.setName(rs.getString("NAME"));
category.setDescription(rs.getString("DESCRIPTION"));
categories.add(category);
}
return categories;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
+ "application categories", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
+ "categories, while executing " + sql, e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public Category getCategory(String name) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
rs = stmt.executeQuery();
if (rs.next()) {
Category category = new Category();
category.setId(rs.getInt("ID"));
category.setName(rs.getString("NAME"));
category.setDescription(rs.getString("DESCRIPTION"));
return category;
}
return null;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
+ "application categories", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
+ "categories, while executing " + sql, e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public void deleteCategory(String name) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
String sql = "DELETE FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to delete the category " + name, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL Exception while trying to delete the category " + name + " while executing the query " +
sql, e);
} finally {
Util.cleanupResources(stmt, null);
}
}
}

@ -90,8 +90,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
if (isBatchExecutionSupported) {
preparedStatement.addBatch();
}
else {
} else {
preparedStatement.execute();
}
}

@ -24,6 +24,7 @@ import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
@ -70,17 +71,20 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setUuid(HelperUtil.generateApplicationUuid());
application.setCreatedAt(new Date());
application.setModifiedAt(new Date());
Platform platform = DataHolder.getInstance().getPlatformManager()
.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier());
if (platform == null) {
throw new NotFoundException("Invalid platform is provided for the application " + application.getUuid());
}
application.setPlatform(platform);
Category category = DataHolder.getInstance().getCategoryManager()
.getCategory(application.getCategory().getName());
if (category == null) {
throw new NotFoundException("Invalid Category is provided for the application " + application.getUuid());
}
application.setCategory(category);
try {
Platform platform = DataHolder.getInstance().getPlatformManager().getPlatform(application.getUser()
.getTenantId(), application.getPlatform().getIdentifier());
if (platform == null) {
throw new NotFoundException("Invalid platform");
}
ConnectionManagerUtil.beginDBTransaction();
// Validating the platform
application.setPlatform(platform);
if (log.isDebugEnabled()) {
log.debug("Application creation pre-conditions are met and the platform mentioned by identifier "
+ platform.getIdentifier() + " is found");
@ -96,7 +100,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycle.setLifecycleStateModifiedAt(new Date());
lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName());
application.setCurrentLifecycle(lifecycle);
application = DAOFactory.getApplicationDAO().createApplication(application);
DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility());
ConnectionManagerUtil.commitDBTransaction();
@ -118,32 +121,47 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
if (!isApplicationOwnerOrAdmin(application.getUuid(), userName, tenantId)) {
throw new ApplicationManagementException("User " + userName + " does not have permissions to edit the "
+ "application with the UUID " + application.getUuid());
throw new ApplicationManagementException(
"User " + userName + " does not have permissions to edit the " + "application with the UUID "
+ application.getUuid());
}
if (this.getApplication(application.getUuid()) != null) {
try {
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
Platform platform = DataHolder.getInstance().getPlatformManager()
.getPlatform(tenantId, application.getPlatform().getIdentifier());
if (platform == null) {
throw new NotFoundException(
"Platform specified by identifier " + application.getPlatform().getIdentifier()
+ " is not found. Please give a valid platform identifier.");
}
application.setPlatform(platform);
ConnectionManagerUtil.beginDBTransaction();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
application.setModifiedAt(new Date());
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(),
application.getVisibility());
modifiedApplication.setVisibility(visibility);
ConnectionManagerUtil.commitDBTransaction();
return modifiedApplication;
} else {
throw new NotFoundException("Platform information not available with the application!");
if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) {
throw new NotFoundException("Platform information not available with the application!");
}
Platform platform = DataHolder.getInstance().getPlatformManager()
.getPlatform(tenantId, application.getPlatform().getIdentifier());
if (platform == null) {
throw new NotFoundException(
"Platform specified by identifier " + application.getPlatform().getIdentifier()
+ " is not found. Please give a valid platform identifier.");
}
application.setPlatform(platform);
if (application.getCategory() != null) {
String applicationCategoryName = application.getCategory().getName();
if (applicationCategoryName == null || applicationCategoryName.isEmpty()) {
throw new ApplicationManagementException(
"Application category name cannot be null or " + "empty. Cannot edit the application.");
}
Category category = DataHolder.getInstance().getCategoryManager()
.getCategory(application.getCategory().getName());
if (category == null) {
throw new NotFoundException(
"Invalid Category is provided for the application " + application.getUuid() + ". "
+ "Cannot edit application");
}
application.setCategory(category);
}
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
application.setModifiedAt(new Date());
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
Visibility visibility = DataHolder.getInstance().getVisibilityManager()
.put(application.getId(), application.getVisibility());
modifiedApplication.setVisibility(visibility);
ConnectionManagerUtil.commitDBTransaction();
return modifiedApplication;
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw e;
@ -388,8 +406,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ValidationException("Username and tenant Id cannot be empty");
}
if (application.getCategory() == null || application.getCategory().getId() == 0) {
throw new ValidationException("Category id cannot be empty");
if (application.getCategory() == null || application.getCategory().getName() == null || application
.getCategory().getName().isEmpty()) {
throw new ValidationException("Category name cannot be empty");
}
if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) {

@ -157,10 +157,10 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
throws ResourceManagementException {
Application application = validateApplication(applicationUUID);
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 "
+ "application " + applicationUUID + " is " + artifactDirectoryPath);
}
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
if (binaryFile != null) {
try {
@ -171,7 +171,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
+ applicationUUID, e);
}
}
}
@Override

@ -18,9 +18,15 @@
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationCategoryManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
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.util.ConnectionManagerUtil;
import java.util.List;
/**
* This class is the default implementation for the CategoryManager.
@ -29,22 +35,76 @@ import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
public class CategoryManagerImpl implements CategoryManager {
@Override
public Category createCategory(Category application) throws ApplicationManagementException {
return null;
public Category createCategory(Category category) throws ApplicationManagementException {
if (category == null) {
throw new ApplicationCategoryManagementException("Category is null. Cannot create a category.");
}
if (category.getName() == null) {
throw new ApplicationCategoryManagementException(
"Application category name cannot be null. Application category creation failed.");
}
if (getCategory(category.getName()) != null) {
throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName()
+ "exists already. Please select a different name");
}
try {
ConnectionManagerUtil.beginDBTransaction();
Category createdCategory = DAOFactory.getCategoryDAO().addCategory(category);
ConnectionManagerUtil.commitDBTransaction();
return createdCategory;
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw e;
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public Category editCategory(int applicationId, Category category) throws ApplicationManagementException {
return null;
public List<Category> getCategories() throws ApplicationManagementException {
try {
ConnectionManagerUtil.openDBConnection();
return DAOFactory.getCategoryDAO().getCategories();
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public void deleteCategory(int applicationId) throws ApplicationManagementException {
public Category getCategory(String name) throws ApplicationManagementException {
if (name == null || name.isEmpty()) {
throw new ApplicationCategoryManagementException("Name cannot be empty or null. Cannot get category");
}
try {
ConnectionManagerUtil.openDBConnection();
return DAOFactory.getCategoryDAO().getCategory(name);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public Category getCategory(Filter filter) throws ApplicationManagementException {
return null;
public void deleteCategory(String name) throws ApplicationManagementException {
Category category = getCategory(name);
if (category == null) {
throw new NotFoundException(
"Category with the name '" + name + "' not found. Cannot delete the " + "non-existing category");
}
try {
ConnectionManagerUtil.beginDBTransaction();
boolean isApplicationExistForCategory = DAOFactory.getApplicationDAO().isApplicationExist(name);
if (isApplicationExistForCategory) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationCategoryManagementException(
"Cannot delete the the category " + name + ". Applications " + "exists for this category");
}
DAOFactory.getCategoryDAO().deleteCategory(name);
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw e;
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
}

@ -21,7 +21,6 @@ package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
import java.io.File;
@ -32,12 +31,15 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
/**
* This is a util class that handles Storage Management related tasks.
*/
public class StorageManagementUtil {
/**
* This method is responsible for creating artifact parent directories in the given path.
*
* @param artifactDirectoryPath Path for the artifact directory.
* @throws ApplicationStorageManagementException Application Storage Management Exception.
* @throws ResourceManagementException Resource Management Exception.
*/
public static void createArtifactDirectory(String artifactDirectoryPath) throws ResourceManagementException {
File artifactDirectory = new File(artifactDirectoryPath);
@ -65,7 +67,6 @@ public class StorageManagementUtil {
artifactDirectory.delete();
}
/**
* To save a file in a given location.
*

@ -44,15 +44,13 @@ CREATE INDEX IF NOT EXISTS FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY (
ID INT NOT NULL AUTO_INCREMENT,
NAME VARCHAR(100) NOT NULL,
NAME VARCHAR(100) NOT NULL UNIQUE,
DESCRIPTION TEXT NULL,
PUBLISHED TINYINT NULL,
PRIMARY KEY (ID));
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Enterprise', 'Enterprise level
applications which the artifacts need to be provided', 1);
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Public', 'Public category in which the
application need to be downloaded from the public application store', 1);
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Sports', 'Applications that involve sports.');
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Education', 'Application related with education');
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('News', 'Applications involving news');
-- -----------------------------------------------------
-- Table `APPM_LIFECYCLE_STATE`

@ -60,17 +60,15 @@ CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TENANT_MAPPING` (
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `APPM_APPLICATION_CATEGORY` (
`ID` INT NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(100) NOT NULL,
`NAME` VARCHAR(100) NOT NULL UNIQUE,
`DESCRIPTION` TEXT NULL,
`PUBLISHED` TINYINT(1) NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB
COMMENT = 'This table contains the data related to the application category';
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Enterprise',
'Enterprise level applications which the artifacts need to be provided', 1);
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Public',
'Public category in which the application need to be downloaded from the public application store', 1);
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Sports', 'Applications that involve sports.');
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Education', 'Application related with education');
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('News', 'Applications involving news');
-- -----------------------------------------------------
-- Table `APPM_LIFECYCLE_STATE`

Loading…
Cancel
Save