summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src
diff options
context:
space:
mode:
authorKartik Hegde <kh00735564@techmahindra.com>2022-11-12 14:29:11 +0530
committerKartik Hegde <kh00735564@techmahindra.com>2022-12-21 12:04:30 +0000
commitcf04a1a714ef4a1df973929dc750232b4d67d7b4 (patch)
treeedd2e6e5074ba58efb98663a1ea1851208895fff /openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src
parentf995db01ee95606b6cded82822a73435ebc190c8 (diff)
Multitenancy in SDC
Issue-ID: SDC-4215 Change-Id: Ie24ba38acc9f1998d4a7e722e8f98456dab9201d Signed-off-by: Kartik Hegde <kh00735564@techmahindra.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java8
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelEntityToDto.java3
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity.java1
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java114
4 files changed, 97 insertions, 29 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java
index 0636b6e599..1c942d46c5 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java
@@ -45,6 +45,8 @@ import org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionReques
import org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelEntityDto;
import org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelRequestDto;
import org.springframework.validation.annotation.Validated;
+import javax.ws.rs.core.Context;
+import javax.servlet.http.HttpServletRequest;
@Path("/v1.0/vendor-license-models")
@Produces(MediaType.APPLICATION_JSON)
@@ -61,13 +63,13 @@ public interface VendorLicenseModels {
@Parameter(description = "Filter to only return Vendor License Models at this status."
+ "Currently supported values: 'ACTIVE' , 'ARCHIVED'."
+ "Default value = 'ACTIVE'.") @QueryParam("Status") String itemStatus,
- @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(RestConstants.USER_ID_HEADER_PARAM) String user);
+ @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(RestConstants.USER_ID_HEADER_PARAM) String user , @Context HttpServletRequest req);
@POST
@Path("/")
- @Operation(description = "Create vendor license model")
+ @Operation(description = "Create vendor license model", responses = @ApiResponse(responseCode = "401", description = "Unauthorized Tenant"))
Response createLicenseModel(@Valid VendorLicenseModelRequestDto request,
- @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(RestConstants.USER_ID_HEADER_PARAM) String user);
+ @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(RestConstants.USER_ID_HEADER_PARAM) String user, @Context HttpServletRequest req);
@DELETE
@Path("/{vlmId}")
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelEntityToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelEntityToDto.java
index 5b0bfb7d73..9a099b83cc 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelEntityToDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelEntityToDto.java
@@ -31,5 +31,8 @@ public class MapVendorLicenseModelEntityToDto extends MappingBase<VendorLicenseM
target.setVendorName(source.getVendorName());
target.setDescription(source.getDescription());
target.setIconRef(source.getIconRef());
+ if (source.getTenant() != null) {
+ target.setTenant(source.getTenant());
+ }
}
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity.java
index 2cbc81980a..d3dbe1dc31 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity.java
@@ -30,5 +30,6 @@ public class MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity extends M
target.setVendorName(source.getVendorName());
target.setDescription(source.getDescription());
target.setIconRef(source.getIconRef());
+ target.setTenant(source.getTenant());
}
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
index ac722a5925..d22751d271 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
@@ -15,6 +15,7 @@
*/
package org.openecomp.sdcrests.vendorlicense.rest.services;
+import org.keycloak.representations.AccessToken;
import org.openecomp.core.dao.UniqueValueDaoFactory;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.sdc.activitylog.ActivityLogManager;
@@ -22,6 +23,7 @@ import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
import org.openecomp.sdc.activitylog.dao.type.ActivityType;
import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.common.util.Multitenancy;
import org.openecomp.sdc.datatypes.model.ItemType;
import org.openecomp.sdc.healing.factory.HealingManagerFactory;
import org.openecomp.sdc.itempermissions.PermissionsManager;
@@ -66,11 +68,22 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.inject.Named;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.*;
+import static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit;
+
+import javax.inject.Named;
import javax.ws.rs.core.Response;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -142,38 +155,87 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
}
@Override
- public Response listLicenseModels(String versionStatus, String itemStatus, String user) {
+ public Response listLicenseModels(String versionStatus, String itemStatus, String user, HttpServletRequest hreq) {
Predicate<Item> itemPredicate = createItemPredicate(versionStatus, itemStatus, user);
GenericCollectionWrapper<ItemDto> results = new GenericCollectionWrapper<>();
MapItemToDto mapper = new MapItemToDto();
- asdcItemManager.list(itemPredicate).stream().sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
- .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class)));
- return Response.ok(results).build();
+ Multitenancy keyaccess= new Multitenancy();
+ if (keyaccess.multiTenancyCheck()) {
+ AccessToken.Access realmAccess = keyaccess.getAccessToken(hreq).getRealmAccess();
+ Set<String> realmroles = realmAccess.getRoles();
+ realmroles.stream().forEach(role -> asdcItemManager.list(itemPredicate).stream().sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
+ .filter(item -> item.getTenant().contains(role))
+ .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class))));
+ return Response.ok(results).build();
+ }
+ else
+ {
+ asdcItemManager.list(itemPredicate).stream().sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
+ .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class)));
+ return Response.ok(results).build();
+ }
}
@Override
- public Response createLicenseModel(VendorLicenseModelRequestDto request, String user) {
- Item item = new Item();
- item.setType(ItemType.vlm.name());
- item.setOwner(user);
- item.setStatus(ItemStatus.ACTIVE);
- item.setName(request.getVendorName());
- item.setDescription(request.getDescription());
- uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
- item = asdcItemManager.create(item);
- uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
- Version version = versioningManager.create(item.getId(), new Version(), null);
- VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
- .applyMapping(request, VendorLicenseModelEntity.class);
- vlm.setId(item.getId());
- vlm.setVersion(version);
- vendorLicenseManager.createVendorLicenseModel(vlm);
- versioningManager.publish(item.getId(), version, "Initial vlm:" + vlm.getVendorName());
- ItemCreationDto itemCreationDto = new ItemCreationDto();
- itemCreationDto.setItemId(item.getId());
- itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
- activityLogManager.logActivity(new ActivityLogEntity(vlm.getId(), version, ActivityType.Create, user, true, "", ""));
- return Response.ok(itemCreationDto).build();
+ public Response createLicenseModel(VendorLicenseModelRequestDto request, String user, HttpServletRequest hreq) {
+ Multitenancy keyaccess= new Multitenancy();
+ if (keyaccess.multiTenancyCheck()) {
+ AccessToken.Access realmAccess = keyaccess.getAccessToken(hreq).getRealmAccess();
+ Set<String> realmroles = realmAccess.getRoles();
+ boolean match = realmroles.contains(request.getTenant());
+ if (match) {
+ Item item = new Item();
+ item.setType(ItemType.vlm.name());
+ item.setOwner(user);
+ item.setStatus(ItemStatus.ACTIVE);
+ item.setName(request.getVendorName());
+ item.setDescription(request.getDescription());
+ item.setTenant(request.getTenant());
+ uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
+ item = asdcItemManager.create(item);
+ uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
+ Version version = versioningManager.create(item.getId(), new Version(), null);
+ VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
+ .applyMapping(request, VendorLicenseModelEntity.class);
+ vlm.setId(item.getId());
+ vlm.setVersion(version);
+ vendorLicenseManager.createVendorLicenseModel(vlm);
+ versioningManager.publish(item.getId(), version, "Initial vlm:" + vlm.getVendorName());
+ ItemCreationDto itemCreationDto = new ItemCreationDto();
+ itemCreationDto.setItemId(item.getId());
+ itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
+ activityLogManager.logActivity(new ActivityLogEntity(vlm.getId(), version, ActivityType.Create, user, true, "", ""));
+ return Response.ok(itemCreationDto).build();
+ }
+ else {
+ LOGGER.error("Unauthorized tenant");
+ return Response.status(401, "Unauthorized tenant").build();
+ }
+ }
+ else
+ {
+ Item item = new Item();
+ item.setType(ItemType.vlm.name());
+ item.setOwner(user);
+ item.setStatus(ItemStatus.ACTIVE);
+ item.setName(request.getVendorName());
+ item.setDescription(request.getDescription());
+ uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
+ item = asdcItemManager.create(item);
+ uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
+ Version version = versioningManager.create(item.getId(), new Version(), null);
+ VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
+ .applyMapping(request, VendorLicenseModelEntity.class);
+ vlm.setId(item.getId());
+ vlm.setVersion(version);
+ vendorLicenseManager.createVendorLicenseModel(vlm);
+ versioningManager.publish(item.getId(), version, "Initial vlm:" + vlm.getVendorName());
+ ItemCreationDto itemCreationDto = new ItemCreationDto();
+ itemCreationDto.setItemId(item.getId());
+ itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
+ activityLogManager.logActivity(new ActivityLogEntity(vlm.getId(), version, ActivityType.Create, user, true, "", ""));
+ return Response.ok(itemCreationDto).build();
+ }
}
@Override