import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
-import io.swagger.v3.oas.annotations.servers.Servers;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
-import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
-import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.ModelBusinessLogic;
import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.Multitenancy;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Controller;
-
+import org.keycloak.representations.AccessToken;
@Path("/v1/")
/**
*
*
*/
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Tags({@io.swagger.v3.oas.annotations.tags.Tag(name = "SDCE-2 APIs")})
-@Servers({@Server(url = "/sdc2/rest")})
+@io.swagger.v3.oas.annotations.tags.Tag(name = "SDCE-2 APIs")
+@Server(url = "/sdc2/rest")
@Controller
public class ElementServlet extends BeGenericServlet {
private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
private final ElementBusinessLogic elementBusinessLogic;
private final ArtifactsBusinessLogic artifactsBusinessLogic;
+ private final ModelBusinessLogic modelBusinessLogic;
@Inject
- public ElementServlet(final UserBusinessLogic userBusinessLogic, final ComponentsUtils componentsUtils,
+ public ElementServlet(final ComponentsUtils componentsUtils,
final ComponentsCleanBusinessLogic componentsCleanBusinessLogic, final ElementBusinessLogic elementBusinessLogic,
- final ArtifactsBusinessLogic artifactsBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
+ final ArtifactsBusinessLogic artifactsBusinessLogic, final ModelBusinessLogic modelBusinessLogic) {
+ super(componentsUtils);
this.componentsCleanBusinessLogic = componentsCleanBusinessLogic;
this.elementBusinessLogic = elementBusinessLogic;
this.artifactsBusinessLogic = artifactsBusinessLogic;
+ this.modelBusinessLogic = modelBusinessLogic;
}
/*
******************************************************************************
@ApiResponse(responseCode = "400", description = "Invalid component type"),
@ApiResponse(responseCode = "409", description = "Restricted operation"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getComponentCategories(
@Parameter(description = "allowed values are resources / services/ products", schema = @Schema(allowableValues = {
ComponentTypeEnum.RESOURCE_PARAM_NAME, ComponentTypeEnum.SERVICE_PARAM_NAME,
@ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
@ApiResponse(responseCode = "409", description = "Category already exists / User not permitted to perform the action"),
@ApiResponse(responseCode = "500", description = "General Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response createComponentCategory(
@Parameter(description = "allowed values are resources /services / products", schema = @Schema(allowableValues = {
ComponentTypeEnum.RESOURCE_PARAM_NAME, ComponentTypeEnum.SERVICE_PARAM_NAME,
throw e;
}
}
-
+
@GET
@Path("/category/{componentType}/{categoryName}/baseTypes")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Get base types for category", method = "GET", summary = "Get base types for category",
- responses = {@ApiResponse(responseCode = "200", description = "Returns base types Ok"),
- @ApiResponse(responseCode = "404", description = "No base types were found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ responses = {@ApiResponse(responseCode = "200", description = "Returns base types Ok"),
+ @ApiResponse(responseCode = "404", description = "No base types were found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
public Response getCategoryBaseTypes(@PathParam(value = "categoryName") final String categoryName,
- @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
+ @PathParam(value = "componentType") final String componentType,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "model", required = false) @QueryParam("model") String modelName) {
try {
final ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
- final Either<List<BaseType>, ActionStatus> either = elementBL.getBaseTypes(categoryName, userId);
-
+ final Either<List<BaseType>, ActionStatus> either = elementBL.getBaseTypes(categoryName, userId, modelName);
+
if (either.isRight() || either.left().value() == null) {
log.debug("No base types were found");
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
} else {
final Map<String, Object> baseTypesMap = new HashMap<>();
baseTypesMap.put("baseTypes", either.left().value());
+ baseTypesMap.put("required", elementBL.isBaseTypeRequired(categoryName));
+ baseTypesMap.put("defaultBaseType", elementBL.getDefaultBaseType(categoryName));
+ baseTypesMap.put("doNotExtendBaseType", elementBL.isDoNotExtendBaseType(categoryName));
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), baseTypesMap);
}
@ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
@ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
@ApiResponse(responseCode = "404", description = "Category not found"), @ApiResponse(responseCode = "500", description = "General Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
@PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
@ApiResponse(responseCode = "404", description = "Parent category wasn't found"),
@ApiResponse(responseCode = "409", description = "Subcategory already exists / User not permitted to perform the action"),
@ApiResponse(responseCode = "500", description = "General Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response createComponentSubCategory(
@Parameter(description = "allowed values are resources / products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
ComponentTypeEnum.PRODUCT_PARAM_NAME}), required = true) @PathParam(value = "componentType") final String componentType,
@ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
@ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
@ApiResponse(responseCode = "404", description = "Category not found"), @ApiResponse(responseCode = "500", description = "General Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
@PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
@PathParam(value = "componentType") final String componentType,
@ApiResponse(responseCode = "404", description = "Parent category or subcategory were not found"),
@ApiResponse(responseCode = "409", description = "Grouping already exists / User not permitted to perform the action"),
@ApiResponse(responseCode = "500", description = "General Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response createComponentGrouping(@Parameter(description = "allowed values are products", schema = @Schema(allowableValues = {
ComponentTypeEnum.PRODUCT_PARAM_NAME}), required = true) @PathParam(value = "componentType") final String componentType,
@Parameter(description = "Parent category unique ID", required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
@ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
@ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
@ApiResponse(responseCode = "404", description = "Category not found"), @ApiResponse(responseCode = "500", description = "General Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response deleteComponentGrouping(@PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId,
@PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
@PathParam(value = "groupingUniqueId") final String groupingUniqueId,
@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
@ApiResponse(responseCode = "200", description = "Returns tags Ok"), @ApiResponse(responseCode = "404", description = "No tags were found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getTags(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("(getTags) Start handle request of {}", url);
@ApiResponse(responseCode = "200", description = "Returns propertyScopes Ok"),
@ApiResponse(responseCode = "404", description = "No propertyScopes were found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getPropertyScopes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("(getPropertyScopes) Start handle request of {}", url);
@ApiResponse(responseCode = "200", description = "Returns artifactTypes Ok"),
@ApiResponse(responseCode = "404", description = "No artifactTypes were found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getArtifactTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
@ApiResponse(responseCode = "404", description = "No followed were found"),
@ApiResponse(responseCode = "404", description = "User not found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getFollowedResourcesServices(@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
try {
log.debug("failed to get followed resources services ");
return buildErrorResponse(followedResourcesServices.right().value());
}
- Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
+ Multitenancy keyaccess= new Multitenancy();
+ if (keyaccess.multiTenancyCheck()) {
+ AccessToken.Access realmAccess = keyaccess.getAccessToken(request).getRealmAccess();
+ Set<String> realmroles = realmAccess.getRoles();
+ Map<String, List<? extends Component>> dataResponse = new HashMap<>();
+ followedResourcesServices.left().value().entrySet().stream()
+ .forEach(component->{component.setValue(component.getValue().stream().filter(cm->realmroles.stream()
+ .anyMatch(role->cm.getTenant().equals(role))).collect(Collectors.toList()));
+ dataResponse.put(component.getKey(), component.getValue());
+ });
+ Object data = RepresentationUtils.toRepresentation(dataResponse);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
+ }
+ else{
+ Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
+ }
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
log.debug("Getting followed resources/services failed with exception", e);
@ApiResponse(responseCode = "404", description = "No resources and services were found"),
@ApiResponse(responseCode = "404", description = "User not found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getCatalogComponents(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
@QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) throws IOException {
try {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext())
- .getCatalogComponents(userId, excludeTypes);
+ .getCatalogComponents(excludeTypes);
if (catalogData.isRight()) {
log.debug("failed to get catalog data");
return buildErrorResponse(catalogData.right().value());
@DELETE
@Path("/inactiveComponents/{componentType}")
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
@Operation(description = "Retrieve ecomp portal menu - MOC", method = "GET", summary = "Retrieve ecomp portal menu", responses = {
@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
@ApiResponse(responseCode = "200", description = "Retrieve ecomp portal menu")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getListOfCsars(@Context final HttpServletRequest request) {
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
"[{\"menuId\":1,\"column\":2,\"text\":\"Design\",\"parentMenuId\":null,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":11,\"column\":1,\"text\":\"ProductDesign\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":12,\"column\":2,\"text\":\"Service\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":21,\"column\":1,\"text\":\"ViewPolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":90,\"column\":1,\"text\":\"4thLevelApp1aR16\",\"parentMenuId\":21,\"url\":\"http://google.com\",\"appid\":null,\"roles\":null}]},{\"menuId\":22,\"column\":2,\"text\":\"UpdatePolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":91,\"column\":1,\"text\":\"4thLevelApp1bR16\",\"parentMenuId\":22,\"url\":\"http://jsonlint.com/\",\"appid\":null,\"roles\":null}]},{\"menuId\":23,\"column\":3,\"text\":\"UpdateRules\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":24,\"column\":4,\"text\":\"CreateSignatures?\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":25,\"column\":5,\"text\":\"Definedata\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null}]}]}]");
@Operation(description = "Retrieve previus and current catalog update time", method = "GET", summary = "Retrieve previus and current catalog update time", responses = {
@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
@ApiResponse(responseCode = "200", description = "Retrieve previus and current catalog update time")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getCatalogUpdateTime(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("(post) Start handle request of {}", url);
- CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime(userId);
+ CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime();
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), catalogUpdateTimestamp);
}
@ApiResponse(responseCode = "200", description = "Returns artifactTypes, ui configuration and sdc version Ok"),
@ApiResponse(responseCode = "404", description = "No artifactTypes were found/no ui configuration were found/no sdc version were found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")})
- @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getConfCategoriesAndVersion(@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
return buildErrorResponse(either.right().value());
}
consolidatedObject.put("categories", either.left().value());
+ consolidatedObject.put("models", modelBusinessLogic.listModels());
consolidatedObject.put("version", getVersion(servletContext));
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getSDCVersion");