Add APIs which are related to application tag management

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 1a3d3215a0
commit ed30867f3a

@ -227,13 +227,18 @@ public interface ApplicationManager {
void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException; void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException;
void addAplicationCategories(List<String> categories) throws ApplicationManagementException; void addAplicationCategories(List<String> categories) throws ApplicationManagementException;
List<Tag> getRegisteredTags() throws ApplicationManagementException; List<Tag> getRegisteredTags() throws ApplicationManagementException;
List<Category> getRegisteredCategories() throws ApplicationManagementException; List<Category> getRegisteredCategories() throws ApplicationManagementException;
void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException; void deleteApplicationTag(int appId, String tagName) throws ApplicationManagementException;
void deleteTag(String tagName) throws ApplicationManagementException;
void deleteUnusedTag(String tagName) throws ApplicationManagementException;
void updateTag(String oldTagName, String newTagName) throws ApplicationManagementException;
} }

@ -53,7 +53,7 @@ public interface ApplicationDAO {
List<Integer> getTagIdsForTagNames (List<String> tagNames, int tenantId) throws ApplicationManagementDAOException; List<Integer> getTagIdsForTagNames (List<String> tagNames, int tenantId) throws ApplicationManagementDAOException;
Integer getTagIdForTagName(String tagName, int tenantId) throws ApplicationManagementDAOException; TagDTO getTagForTagName(String tagName, int tenantId) throws ApplicationManagementDAOException;
List<Integer> getDistinctTagIdsInTagMapping() throws ApplicationManagementDAOException; List<Integer> getDistinctTagIdsInTagMapping() throws ApplicationManagementDAOException;
@ -61,11 +61,21 @@ public interface ApplicationDAO {
List<String> getAppTags(int appId, int tenantId) throws ApplicationManagementDAOException; List<String> getAppTags(int appId, int tenantId) throws ApplicationManagementDAOException;
void deleteTagMapping (List<Integer> tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException; boolean hasTagMapping(int tagId, int appId, int tenantId) throws ApplicationManagementDAOException;
void deleteTagMapping (Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException; boolean hasTagMapping(int tagId, int tenantId) throws ApplicationManagementDAOException;
void deleteTagMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException; void deleteApplicationTags(List<Integer> tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteApplicationTags(Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteApplicationTags(int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteTagMapping(int tagId, int tenantId) throws ApplicationManagementDAOException;
void deleteTag(int tagId, int tenantId) throws ApplicationManagementDAOException;
void updateTag(TagDTO tagDTO, int tenantId) throws ApplicationManagementDAOException;
List<String> getAppCategories (int appId, int tenantId) throws ApplicationManagementDAOException; List<String> getAppCategories (int appId, int tenantId) throws ApplicationManagementDAOException;

@ -901,7 +901,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public Integer getTagIdForTagName(String tagName, int tenantId) throws ApplicationManagementDAOException { public TagDTO getTagForTagName(String tagName, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get tag id for given tag name."); log.debug("Request received in DAO Layer to get tag id for given tag name.");
} }
@ -916,11 +916,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
ps.setInt(2, tenantId); ps.setInt(2, tenantId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) { if (rs.next()) {
return rs.getInt("ID"); TagDTO tagDTO = new TagDTO();
tagDTO.setId(rs.getInt("ID"));
tagDTO.setTagName(tagName);
return tagDTO;
} }
} }
} }
return -1; return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when getting tag Id for given tag name", e); "Error occurred while obtaining the DB connection when getting tag Id for given tag name", e);
@ -1019,7 +1022,69 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public void deleteTagMapping (List<Integer> tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException{ public boolean hasTagMapping (int tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to verify whether tag is associated with an application.");
}
Connection conn;
String sql = "SELECT tm.AP_APP_ID AS ID "
+ "FROM AP_APP_TAG_MAPPING tm "
+ "WHERE "
+ "tm.AP_APP_TAG_ID = ? AND "
+ "tm.AP_APP_ID = ? AND "
+ "tm.TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tagId);
stmt.setInt(2, applicationId);
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
return rs.next();
}
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when verifying the existence of a tag mapping",
e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when verifying the existence of a tag mapping.",
e);
}
}
@Override
public boolean hasTagMapping (int tagId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to verify whether tag is associated with at least one application.");
}
Connection conn;
String sql = "SELECT tm.AP_APP_ID AS ID "
+ "FROM AP_APP_TAG_MAPPING tm "
+ "WHERE "
+ "tm.AP_APP_TAG_ID = ? AND "
+ "tm.TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tagId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
return rs.next();
}
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when verifying the existence of a tag mapping",
e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when verifying the existence of a tag mapping.",
e);
}
}
@Override
public void deleteApplicationTags(List<Integer> tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mappings."); log.debug("Request received in DAO Layer to delete Tag mappings.");
} }
@ -1050,7 +1115,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public void deleteTagMapping (Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException{ public void deleteApplicationTags(Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mapping."); log.debug("Request received in DAO Layer to delete Tag mapping.");
} }
@ -1078,9 +1143,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public void deleteTagMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException{ public void deleteApplicationTags(int applicationId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mappings."); log.debug("Request received in DAO Layer to delete application tags.");
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " String sql = "DELETE FROM "
@ -1090,21 +1155,109 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "tm.TENANT_ID = ?"; + "tm.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, applicationId); stmt.setInt(1, applicationId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when deleting tag mapping of application ID: " "Error occurred while obtaining the DB connection when deleting application tags for application ID: "
+ applicationId , e); + applicationId, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when deleting tag mapping of application ID: " throw new ApplicationManagementDAOException(
+ applicationId, e); "Error occurred when deleting application tags for application ID: " + applicationId, e);
} }
} }
@Override
public void deleteTagMapping(int tagId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mappings.");
}
Connection conn;
String sql = "DELETE FROM " +
"AP_APP_TAG_MAPPING tm " +
"WHERE " +
"tm.AP_APP_ID = ? AND " +
"tm.TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tagId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when deleting tag mapping of tag ID: " + tagId,
e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when deleting tag mapping of tag ID: " + tagId,
e);
}
}
@Override
public void deleteTag(int tagId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mappings.");
}
Connection conn;
String sql = "DELETE FROM " +
"AP_APP_TAG tag " +
"WHERE " +
"tag.ID = ? AND " +
"tag.TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tagId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when deleting tag which has ID: " + tagId,
e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when deleting tag which has ID: " + tagId,
e);
}
}
@Override
public void updateTag(TagDTO tagDTO, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to update the Tag.");
}
Connection conn;
String sql = "UPDATE " +
"AP_APP_TAG tag " +
"SET tag.TAG_NAME = ? " +
"WHERE " +
"tag.ID = ? AND " +
"tag.TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, tagDTO.getTagName());
stmt.setInt(1, tagDTO.getId());
stmt.setInt(2, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when updating tag which has ID: " + tagDTO
.getId(), e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred when updating tag which has ID: " + tagDTO.getId(), e);
}
}
@Override @Override
public List<String> getAppCategories(int appId, int tenantId) throws ApplicationManagementDAOException { public List<String> getAppCategories(int appId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -1201,7 +1201,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds); this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds);
this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds); this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds);
this.applicationDAO.deleteTagMapping(applicationId, tenantId); this.applicationDAO.deleteApplicationTags(applicationId, tenantId);
this.applicationDAO.deleteCategoryMapping(applicationId, tenantId); this.applicationDAO.deleteCategoryMapping(applicationId, tenantId);
this.applicationDAO.deleteApplication(applicationId, tenantId); this.applicationDAO.deleteApplication(applicationId, tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
@ -1809,7 +1809,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
if (!removingTagList.isEmpty()) { if (!removingTagList.isEmpty()) {
List<Integer> removingTagIds = this.applicationDAO.getTagIdsForTagNames(removingTagList, tenantId); List<Integer> removingTagIds = this.applicationDAO.getTagIdsForTagNames(removingTagList, tenantId);
this.applicationDAO.deleteTagMapping(removingTagIds, applicationId, tenantId); this.applicationDAO.deleteApplicationTags(removingTagIds, applicationId, tenantId);
applicationDAO.deleteTags(removingTagList, applicationId, tenantId); applicationDAO.deleteTags(removingTagList, applicationId, tenantId);
} }
} }
@ -1900,21 +1900,104 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException { public void deleteApplicationTag(int appId, String tagName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ApplicationDTO applicationDTO = getApplication(appId); ApplicationDTO applicationDTO = getApplication(appId);
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
int tagId = applicationDAO.getTagIdForTagName(tagName, tenantId); TagDTO tag = applicationDAO.getTagForTagName(tagName, tenantId);
if (tagId == -1){ if (tag == null){
String msg = "Couldn't found a tag for tag name " + tagName + "."; String msg = "Couldn't found a tag for tag name " + tagName + ".";
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
applicationDAO.deleteTagMapping(tagId, applicationDTO.getId(), tenantId); if (applicationDAO.hasTagMapping(tag.getId(), applicationDTO.getId(), tenantId)){
applicationDAO.deleteApplicationTags(tag.getId(), applicationDTO.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction();
} else {
String msg = "Tag " + tagName + " is not an application tag. Application ID: " + appId;
log.error(msg);
throw new BadRequestException(msg);
}
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Id or deleting tag mapping from the system.";
log.error(msg);
throw new ApplicationManagementException(msg);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public void deleteTag(String tagName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
TagDTO tag = applicationDAO.getTagForTagName(tagName, tenantId);
if (tag == null){
String msg = "Couldn't found a tag for tag name " + tagName + ".";
log.error(msg);
throw new NotFoundException(msg);
}
if (applicationDAO.hasTagMapping(tag.getId(), tenantId)){
applicationDAO.deleteTagMapping(tag.getId(), tenantId);
}
applicationDAO.deleteTag(tag.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Id or deleting the tag from the system.";
log.error(msg);
throw new ApplicationManagementException(msg);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public void deleteUnusedTag(String tagName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
TagDTO tag = applicationDAO.getTagForTagName(tagName, tenantId);
if (tag == null){
String msg = "Couldn't found a tag for tag name " + tagName + ".";
log.error(msg);
throw new NotFoundException(msg);
}
if (applicationDAO.hasTagMapping(tag.getId(), tenantId)){
String msg =
"Tag " + tagName + " is used for applications. Hence it is not permitted to delete the tag "
+ tagName;
log.error(msg);
throw new ForbiddenException(msg);
}
applicationDAO.deleteTag(tag.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Ids or deleting the tag from the system.";
log.error(msg);
throw new ApplicationManagementException(msg);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public void updateTag(String oldTagName, String newTagName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
TagDTO tag = applicationDAO.getTagForTagName(oldTagName, tenantId);
if (tag == null){
String msg = "Couldn't found a tag for tag name " + oldTagName + ".";
log.error(msg);
throw new NotFoundException(msg);
}
tag.setTagName(newTagName);
applicationDAO.updateTag(tag, tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Ids or deleting tag mapping from the system."; String msg = "Error occurred when getting tag Ids or deleting the tag from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} finally { } finally {

@ -831,12 +831,16 @@ public interface ApplicationManagementPublisherAPI {
code = 200, code = 200,
message = "OK. \n Successfully delete Application tags.", message = "OK. \n Successfully delete Application tags.",
response = ApplicationList.class), response = ApplicationList.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Given tag is not an associated tag for the given application."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while deleting application tags.", message = "Internal Server Error. \n Error occurred while deleting application tags.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response deleteTagMapping( Response deleteApplicationTag(
@ApiParam( @ApiParam(
name = "appId", name = "appId",
value = "ID of the Application", value = "ID of the Application",
@ -849,6 +853,92 @@ public interface ApplicationManagementPublisherAPI {
@PathParam("tagName") String tagName @PathParam("tagName") String tagName
); );
@DELETE
@Path("/tags/{tagName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete application tag",
notes = "This will delete application tag",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete registered tag.",
response = ApplicationList.class),
@ApiResponse(
code = 403,
message = "Don't have permission to delete the application tag."),
@ApiResponse(
code = 404,
message = "NOT FOUND. \n Couldn't found a tag for the given tag name.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting registered tag.",
response = ErrorResponse.class)
})
Response deleteUnusedTag(
@ApiParam(
name = "tagName",
value = "Tag Name",
required = true)
@PathParam("tagName") String tagName
);
@PUT
@Path("/tags/{oldTagName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "update an application tag",
notes = "This will update application tag",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully update the registered tag.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "NOT FOUND. \n Couldn't found a tag for the given tag name.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while updating registered tag.",
response = ErrorResponse.class)
})
Response modifyTagName(
@ApiParam(
name = "oldTagName",
value = "Existing Tag Name",
required = true)
@PathParam("oldTagName") String oldTagName,
@ApiParam(
name = "tag",
value = "Modifying Tag Name",
required = true)
@QueryParam("tag") String newTagName
);
@GET @GET
@Path("/categories") @Path("/categories")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)

@ -151,4 +151,39 @@ public interface ApplicationManagementPublisherAdminAPI {
value = "application ID", value = "application ID",
required = true) required = true)
@PathParam("appId") int applicatioId); @PathParam("appId") int applicatioId);
@DELETE
@Path("/tags/{tagName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Delete application tag",
notes = "This will delete application tag",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully delete registered tag.",
response = ApplicationList.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting registered tag.",
response = ErrorResponse.class)
})
Response deleteTag(
@ApiParam(
name = "tagName",
value = "Tag Name",
required = true)
@PathParam("tagName") String tagName
);
} }

@ -499,18 +499,22 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@Consumes("application/json") @Consumes("application/json")
@Path("/{appId}/tags/{tagName}") @Path("/{appId}/tags/{tagName}")
public Response deleteTagMapping( public Response deleteApplicationTag(
@PathParam("appId") int appId, @PathParam("appId") int appId,
@PathParam("tagName") String tagName) { @PathParam("tagName") String tagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
applicationManager.deleteTagMapping(appId, tagName); applicationManager.deleteApplicationTag(appId, tagName);
String msg = "Tag " + tagName + " is deleted successfully."; String msg = "Tag " + tagName + " is deleted successfully.";
return Response.status(Response.Status.OK).entity(msg).build(); return Response.status(Response.Status.OK).entity(msg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = e.getMessage(); String msg = e.getMessage();
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting registered tag."; String msg = "Error Occurred while deleting registered tag.";
log.error(msg); log.error(msg);
@ -518,6 +522,55 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
@DELETE
@Override
@Consumes("application/json")
@Path("/tags/{tagName}")
public Response deleteUnusedTag(
@PathParam("tagName") String tagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteUnusedTag(tagName);
String msg = "Tag " + tagName + " is deleted successfully.";
return Response.status(Response.Status.OK).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting unused tag.";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@PUT
@Override
@Consumes("application/json")
@Path("/tags/{oldTagName}")
public Response modifyTagName(
@PathParam("oldTagName") String oldTagName,
@QueryParam("tag") String newTagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.updateTag(oldTagName, newTagName);
String msg = "Tag " + oldTagName + " is updated to " + newTagName + " successfully.";
return Response.status(Response.Status.OK).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while updating registered tag.";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET @GET
@Override @Override
@Consumes("application/json") @Consumes("application/json")

@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ApplicationManagementPublisherAdminAPI; import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ApplicationManagementPublisherAdminAPI;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
@ -94,4 +95,26 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
} }
} }
@DELETE
@Override
@Consumes("application/json")
@Path("/tags/{tagName}")
public Response deleteTag(
@PathParam("tagName") String tagName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.deleteTag(tagName);
String msg = "Tag " + tagName + " is deleted successfully.";
return Response.status(Response.Status.OK).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting registered tag.";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
} }

Loading…
Cancel
Save