import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.apache.commons.collections4.ListUtils;
import org.openecomp.sdc.be.components.impl.ArtifactTypeBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
@ApiResponse(responseCode = "404", description = "Data types not found")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getAllDataTypesFromAllModels(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @QueryParam("excludePrimitives") @DefaultValue("false") String excludePrimitives) {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
init();
validateUserExist(responseWrapper, userWrapper, userId);
if (responseWrapper.isEmpty()) {
+ final boolean exclude = Boolean.parseBoolean(excludePrimitives);
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("Start handle request of {} - modifier id is {}", url, userId);
resourceBusinessLogic.getApplicationDataTypeCache().refreshDataTypesCacheIfStale();
final List<Map<String, DataTypeDefinition>> dataTypesList = new ArrayList<>();
List<Model> models = modelOperation.findAllModels();
- Model defaultModel = new Model();
- defaultModel.setName(null);
- models.add(defaultModel);
+ models.add(new Model(null));
models.forEach(model -> {
final Map<String, DataTypeDefinition> dataTypes = resourceBusinessLogic.getComponentsUtils()
.getAllDataTypes(resourceBusinessLogic.getApplicationDataTypeCache(), model.getName());
- dataTypesList.add(dataTypes);
+ if (exclude) {
+ dataTypesList.add(dataTypes.entrySet().stream().filter(entry -> !ToscaPropertyType.isScalarType(entry.getKey()))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
+ } else {
+ dataTypesList.add(dataTypes);
+ }
});
String dataTypeJson = gson.toJson(dataTypesList);
Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
public Response getAllToscaArtifactTypes(@Parameter(description = "Model name") @QueryParam("model") String model,
@Context final HttpServletRequest request, @HeaderParam(Constants.USER_ID_HEADER) String creator) {
try {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), artifactTypeBusinessLogic.getAllToscaArtifactTypes(model));
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ artifactTypeBusinessLogic.getAllToscaArtifactTypes(model));
} catch (final BusinessException e) {
throw e;
} catch (final Exception e) {
}
private boolean checkFirstItem(String left, String right) {
- if (left != null && left.equals(right)) {
- return true;
- }
- return false;
+ return left != null && left.equals(right);
}
private String buildStringForMatch(List<String> pathOfInstances, int level) {
if (dataTypeUidstoModels != null) {
log.trace("Number of data types to load is {}", dataTypeUidstoModels.size());
- for (Map.Entry<String, List<String>> entry : dataTypeUidstoModels.entrySet()) {
- log.trace("Going to fetch data type with uid {}", entry.getKey());
- Either<DataTypeDefinition, JanusGraphOperationStatus> dataTypeByUid = this
- .getAndAddDataTypeByUid(entry.getKey(), allDataTypesFound);
+ for (final Map.Entry<String, List<String>> entry : dataTypeUidstoModels.entrySet()) {
+ final String key = entry.getKey();
+ log.trace("Going to fetch data type with uid {}", key);
+ final Either<DataTypeDefinition, JanusGraphOperationStatus> dataTypeByUid = this.getAndAddDataTypeByUid(key, allDataTypesFound);
if (dataTypeByUid.isRight()) {
JanusGraphOperationStatus status = dataTypeByUid.right().value();
if (status == JanusGraphOperationStatus.NOT_FOUND) {
}
for (final String model : entry.getValue()) {
if (!dataTypes.containsKey(model)) {
- dataTypes.put(model, new HashMap<String, DataTypeDefinition>());
+ dataTypes.put(model, new HashMap<>());
}
DataTypeDefinition dataTypeDefinition = allDataTypesFound.get(entry.getKey());
dataTypes.get(model).put(dataTypeDefinition.getName(), dataTypeDefinition);
}
}
-
}
if (log.isTraceEnabled()) {
if (result.isRight()) {
return getDerivedResult == StorageOperationStatus.NOT_FOUND;
}
- /*
- * @Override public PropertyOperation getPropertyOperation() { return this; }
- */
public JanusGraphOperationStatus fillPropertiesList(String uniqueId, NodeTypeEnum nodeType, Consumer<List<PropertyDefinition>> propertySetter) {
Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> findPropertiesRes = findPropertiesifExist(uniqueId, nodeType);
if (findPropertiesRes.isRight()) {