diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java index 52c3698f9d..d1110df432 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java @@ -57,7 +57,6 @@ import org.wso2.carbon.identity.api.server.application.management.v1.ResidentApplication; import org.wso2.carbon.identity.api.server.application.management.v1.SAML2Configuration; import org.wso2.carbon.identity.api.server.application.management.v1.SAML2ServiceProvider; -import org.wso2.carbon.identity.api.server.application.management.v1.TagsPatchRequest; import org.wso2.carbon.identity.api.server.application.management.v1.WSTrustConfiguration; import org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils; import org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.ApiModelToServiceProvider; @@ -84,8 +83,6 @@ import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; import org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo; import org.wso2.carbon.identity.application.common.model.ApplicationTagsItem; -import org.wso2.carbon.identity.application.common.model.ApplicationTagsPatch; -import org.wso2.carbon.identity.application.common.model.ApplicationTagsPatch.ApplicationTagsPatchBuilder.OperationEnum; import org.wso2.carbon.identity.application.common.model.AuthenticationStep; import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.IdentityProvider; @@ -93,8 +90,6 @@ import org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig; import org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig; import org.wso2.carbon.identity.application.common.model.InboundConfigurationProtocol; -import org.wso2.carbon.identity.application.common.model.ListValue; -import org.wso2.carbon.identity.application.common.model.ListValue.ListValueBuilder; import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.SpFileContent; @@ -862,8 +857,6 @@ public String createApplication(ApplicationModel applicationModel, String templa public void patchApplication(String applicationId, ApplicationPatchModel applicationPatchModel) { ServiceProvider appToUpdate = cloneApplication(applicationId); - //Setting an empty array to avoid updating same tags again. - appToUpdate.setTags(new ArrayList<>()); if (applicationPatchModel != null) { new UpdateServiceProvider().apply(appToUpdate, applicationPatchModel); } @@ -873,44 +866,12 @@ public void patchApplication(String applicationId, ApplicationPatchModel applica String username = ContextLoader.getUsernameFromContext(); getApplicationManagementService() .updateApplicationByResourceId(applicationId, appToUpdate, tenantDomain, username); - if (applicationPatchModel.getTags() != null) { - getApplicationManagementService().updateApplicationTags(appToUpdate.getApplicationID(), - getApplicationTagsPatchModel(applicationPatchModel.getTags()), tenantDomain); - } } catch (IdentityApplicationManagementException e) { String msg = "Error patching application with id: " + applicationId; throw handleIdentityApplicationManagementException(e, msg); } } - private List getApplicationTagsPatchModel(List tagsPatchModel) { - - List applicationTagsPatch = new ArrayList<>(); - - for (TagsPatchRequest tagsPatch: tagsPatchModel) { - OperationEnum operation; - switch (tagsPatch.getOperation().toString()) { - case "ADD": - operation = OperationEnum.ADD; - break; - case "REMOVE": - operation = OperationEnum.REMOVE; - break; - default: - operation = null; - } - - List patchTags = tagsPatch.getTags().stream() - .map(tag -> new ListValueBuilder().value(tag.getValue()).build()) - .collect(Collectors.toList()); - - applicationTagsPatch.add(new ApplicationTagsPatch.ApplicationTagsPatchBuilder() - .operation(operation) - .tags(patchTags).build()); - } - return applicationTagsPatch; - } - public void deleteApplication(String applicationId) { String username = ContextLoader.getUsernameFromContext(); diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ApiModelToServiceProvider.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ApiModelToServiceProvider.java index ad1939542c..c4bbf8b7d4 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ApiModelToServiceProvider.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ApiModelToServiceProvider.java @@ -28,9 +28,9 @@ import org.wso2.carbon.identity.application.common.model.ApplicationTagsItem.ApplicationTagsItemBuilder; import org.wso2.carbon.identity.application.common.model.ServiceProvider; -import java.util.ArrayList; import java.util.List; import java.util.function.Function; +import java.util.stream.Collectors; import static org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.setIfNotNull; @@ -104,10 +104,9 @@ private void addAdvancedConfigurationToApplication(ServiceProvider application, private void addApplicationTagsToApplication(ServiceProvider application, List tags) { if (tags != null) { - List tagsList = new ArrayList<>(); - for (ListValue tag: tags) { - tagsList.add(new ApplicationTagsItemBuilder().id(tag.getValue()).build()); - } + List tagsList = tags.stream() + .map(tag -> new ApplicationTagsItemBuilder().id(tag.getValue()).build()) + .collect(Collectors.toList()); setIfNotNull(tagsList, application::setTags); } } diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateServiceProvider.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateServiceProvider.java index d88f056b5f..778e380d55 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateServiceProvider.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateServiceProvider.java @@ -15,15 +15,23 @@ */ package org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application; +import org.springframework.util.CollectionUtils; import org.wso2.carbon.identity.api.server.application.management.v1.AdvancedApplicationConfiguration; import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationPatchModel; import org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationSequence; import org.wso2.carbon.identity.api.server.application.management.v1.ClaimConfiguration; +import org.wso2.carbon.identity.api.server.application.management.v1.ListValue; import org.wso2.carbon.identity.api.server.application.management.v1.ProvisioningConfiguration; +import org.wso2.carbon.identity.api.server.application.management.v1.TagsPatchRequest; import org.wso2.carbon.identity.api.server.application.management.v1.core.functions.UpdateFunction; import org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.provisioning.UpdateProvisioningConfiguration; +import org.wso2.carbon.identity.application.common.model.ApplicationTagsItem; +import org.wso2.carbon.identity.application.common.model.ApplicationTagsItem.ApplicationTagsItemBuilder; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import java.util.List; +import java.util.stream.Collectors; + import static org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.setIfNotNull; /** @@ -44,6 +52,7 @@ public void apply(ServiceProvider serviceProvider, ApplicationPatchModel applica patchAuthenticationSequence(applicationPatchModel.getAuthenticationSequence(), serviceProvider); patchAdvancedConfiguration(serviceProvider, applicationPatchModel.getAdvancedConfigurations()); patchProvisioningConfiguration(applicationPatchModel.getProvisioningConfigurations(), serviceProvider); + patchApplicationTags(applicationPatchModel.getTags(), serviceProvider); } private void patchClaimConfiguration(ServiceProvider serviceProvider, ClaimConfiguration claimConfiguration) { @@ -76,4 +85,28 @@ private void patchProvisioningConfiguration(ProvisioningConfiguration provisioni new UpdateProvisioningConfiguration().apply(serviceProvider, provisioningConfigurations); } } + + private void patchApplicationTags(List tags, ServiceProvider serviceProvider) { + + if (!CollectionUtils.isEmpty(tags)) { + List tagIdList = serviceProvider.getTags().stream().map(ApplicationTagsItem::getId) + .collect(Collectors.toList()); + for (TagsPatchRequest patchReq: tags) { + + if (patchReq.getOperation().toString().equals("ADD")) { + List addingTagIdList = patchReq.getTags().stream().map(ListValue::getValue) + .collect(Collectors.toList()); + tagIdList.addAll(addingTagIdList); + continue; + } + if (patchReq.getOperation().toString().equals("REMOVE")) { + List removingTagIdList = patchReq.getTags().stream().map(ListValue::getValue) + .collect(Collectors.toList()); + tagIdList.removeAll(removingTagIdList); + } + } + serviceProvider.setTags(tagIdList.stream().map(id -> new ApplicationTagsItemBuilder().id(id).build()) + .collect(Collectors.toList())); + } + } } diff --git a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.common/pom.xml b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.common/pom.xml index 9d71780848..fbcb8bb3f4 100644 --- a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.common/pom.xml @@ -24,12 +24,12 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.application.tag.management - 1.2.81-SNAPSHOT + 1.2.85-SNAPSHOT ../pom.xml org.wso2.carbon.identity.api.server.application.tag.management.common - 1.2.81-SNAPSHOT + 1.2.85-SNAPSHOT jar diff --git a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/pom.xml index aaf1a1af20..5478a8a59f 100644 --- a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/pom.xml @@ -24,7 +24,7 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.application.tag.management - 1.2.81-SNAPSHOT + 1.2.85-SNAPSHOT ../pom.xml diff --git a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/core/ServerApplicationTagManagementService.java b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/core/ServerApplicationTagManagementService.java index e6a32aedae..6c52b6b300 100644 --- a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/core/ServerApplicationTagManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/core/ServerApplicationTagManagementService.java @@ -160,7 +160,8 @@ public ApplicationTagsListResponse getAllApplicationTags(Integer offset, Integer public ApplicationTagResponse getApplicationTagById(String tagId) { try { - ApplicationTagsItem applicationTag = ApplicationTagManagementServiceHolder.getApplicationTagManager() + org.wso2.carbon.identity.application.common.model.ApplicationTagsListItem applicationTag = + ApplicationTagManagementServiceHolder.getApplicationTagManager() .getApplicationTagById(tagId, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); if (applicationTag == null) { throw ApplicationTagMgtEndpointUtil.handleException(Response.Status.NOT_FOUND, @@ -215,18 +216,19 @@ private ApplicationTag createApplicationTag(ApplicationTagModel applicationTag) } /** - * Build ApplicationTagsListItem from the ApplicationTagsItem. + * Build ApplicationTagResponse from the ApplicationTagsListItem. * * @param applicationTag Application Tag Item. * @return ApplicationTagsListItem. */ - private ApplicationTagResponse buildApplicationTagResponse(ApplicationTagsItem applicationTag) { + private ApplicationTagResponse buildApplicationTagResponse( + org.wso2.carbon.identity.application.common.model.ApplicationTagsListItem applicationTag) { return new ApplicationTagResponse() .id(applicationTag.getId()) .name(applicationTag.getName()) .colour(applicationTag.getColour()) - .associatedAppsCount(0); + .associatedAppsCount(applicationTag.getAssociatedAppsCount()); } /** diff --git a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/impl/ApplicationsTagsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/impl/ApplicationsTagsApiServiceImpl.java index dbda428d4b..6c654fb1f1 100644 --- a/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/impl/ApplicationsTagsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.application.tag.management/org.wso2.carbon.identity.api.server.application.tag.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/tag/management/v1/impl/ApplicationsTagsApiServiceImpl.java @@ -57,7 +57,7 @@ public Response deleteApplicationTag(String tagId) { } @Override - public Response getAllApplicationTags(Integer offset, Integer limit, String filter) { + public Response getAllApplicationTags(Integer limit, Integer offset, String filter) { return Response.ok().entity(serverApplicationTagManagementService.getAllApplicationTags(offset, limit, filter)).build(); diff --git a/components/org.wso2.carbon.identity.api.server.application.tag.management/pom.xml b/components/org.wso2.carbon.identity.api.server.application.tag.management/pom.xml index 55c4224da7..a28cd13ca9 100644 --- a/components/org.wso2.carbon.identity.api.server.application.tag.management/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.application.tag.management/pom.xml @@ -23,12 +23,12 @@ identity-api-server org.wso2.carbon.identity.server.api - 1.2.81-SNAPSHOT + 1.2.85-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.identity.api.server.application.tag.management - 1.2.81-SNAPSHOT + 1.2.85-SNAPSHOT pom diff --git a/pom.xml b/pom.xml index a66b3a1bf1..2d8a40db27 100644 --- a/pom.xml +++ b/pom.xml @@ -408,7 +408,13 @@ org.wso2.carbon.identity.server.api - + org.wso2.carbon.identity.api.server.api.resource.common + ${project.version} + provided + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.application.tag.management.common ${project.version} provided