aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/ItemPermissions.java53
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/mapping/MapItemPermissionsToItemPermissionsDto.java20
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/services/ItemPermissionsImpl.java52
3 files changed, 125 insertions, 0 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/ItemPermissions.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/ItemPermissions.java
new file mode 100644
index 0000000000..e73595c67b
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/ItemPermissions.java
@@ -0,0 +1,53 @@
+package org.openecomp.sdcrests.itempermissions.rest;
+
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.openecomp.sdcrests.itempermissions.types.ItemPermissionsDto;
+import org.openecomp.sdcrests.itempermissions.types.ItemPermissionsRequestDto;
+import org.springframework.validation.annotation.Validated;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM;
+import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG;
+
+/**
+ * Created by ayalaben on 6/18/2017.
+ */
+@Path("/v1.0/items/{itemId}/permissions")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+@Api(value = "Item Permissions")
+@Validated
+public interface ItemPermissions {
+
+ @GET
+ @Path("/")
+ @ApiOperation(value = "List users permissions assigned on item",
+ response = ItemPermissionsDto.class,
+ responseContainer = "List")
+
+ Response list(@PathParam("itemId") String itemId,
+ @HeaderParam(USER_ID_HEADER_PARAM) String user);
+
+ @PUT
+ @Path("/{permission}")
+ @ApiOperation(value = "Update useres permission on item")
+ Response updatePermissions(@Valid ItemPermissionsRequestDto request,
+ @PathParam("itemId") String itemId,
+ @PathParam("permission") String permission,
+ @NotNull(message = USER_MISSING_ERROR_MSG)
+ @HeaderParam(USER_ID_HEADER_PARAM) String user);
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/mapping/MapItemPermissionsToItemPermissionsDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/mapping/MapItemPermissionsToItemPermissionsDto.java
new file mode 100644
index 0000000000..88c3d4d74e
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/mapping/MapItemPermissionsToItemPermissionsDto.java
@@ -0,0 +1,20 @@
+package org.openecomp.sdcrests.itempermissions.rest.mapping;
+
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
+import org.openecomp.sdcrests.itempermissions.types.ItemPermissionsDto;
+import org.openecomp.sdcrests.mapping.MappingBase;
+
+/**
+ * Created by ayalaben on 6/18/2017.
+ */
+
+public class MapItemPermissionsToItemPermissionsDto extends
+ MappingBase<ItemPermissionsEntity, ItemPermissionsDto> {
+
+
+ @Override
+ public void doMapping(ItemPermissionsEntity source, ItemPermissionsDto target) {
+ target.setUserId(source.getUserId());
+ target.setPermission(source.getPermission());
+ }
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/services/ItemPermissionsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/services/ItemPermissionsImpl.java
new file mode 100644
index 0000000000..4fe93c20ac
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-permissions-rest/item-permissions-rest-services/src/main/java/org/openecomp/sdcrests/itempermissions/rest/services/ItemPermissionsImpl.java
@@ -0,0 +1,52 @@
+//package org.openecomp.sdcrests.itempermissions.rest.mapping.mapping.services;
+package org.openecomp.sdcrests.itempermissions.rest.services;
+
+
+import org.openecomp.sdc.itempermissions.ItemPermissionsManager;
+import org.openecomp.sdc.itempermissions.ItemPermissionsManagerFactory;
+import org.openecomp.sdcrests.itempermissions.rest.ItemPermissions;
+import org.openecomp.sdcrests.itempermissions.rest.mapping.MapItemPermissionsToItemPermissionsDto;
+import org.openecomp.sdcrests.itempermissions.types.ItemPermissionsDto;
+import org.openecomp.sdcrests.itempermissions.types.ItemPermissionsRequestDto;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
+
+/**
+ * Created by ayalaben on 6/18/2017.
+ */
+
+@Named
+@Service("itemPermissions")
+@Scope(value = "prototype")
+public class ItemPermissionsImpl implements ItemPermissions {
+
+ private ItemPermissionsManager itemPermissionsManager =
+ ItemPermissionsManagerFactory.getInstance().createInterface();
+
+ @Override
+ public Response list(String itemId, String user) {
+
+ GenericCollectionWrapper<ItemPermissionsDto> results = new GenericCollectionWrapper<>();
+ MapItemPermissionsToItemPermissionsDto mapper = new MapItemPermissionsToItemPermissionsDto();
+
+ itemPermissionsManager.listItemPermissions(itemId)
+ .forEach(itemPermission -> results.add(mapper.applyMapping
+ (itemPermission, ItemPermissionsDto.class)));
+
+ return Response.ok(results).build();
+ }
+
+ @Override
+ public Response updatePermissions(ItemPermissionsRequestDto request, String itemId,
+ String permission, String user) {
+
+ itemPermissionsManager.updateItemPermissions(itemId,permission,request.getAddedUsersIds(),
+ request.getRemovedUsersIds());
+
+ return Response.ok().build();
+ }
+}