use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class AbstractComponentInstanceResource method putId.
@POST
@Path("localName")
@Consumes(MediaType.APPLICATION_JSON)
public Response putId(RenameApiData data) {
DefinitionsChildId newId;
newId = BackendUtils.getDefinitionsChildId(this.getId().getClass(), this.getId().getNamespace().getDecoded(), data.localname, false);
if (data.renameAllComponents) {
return RestUtils.renameAllVersionsOfOneDefinition(this.getId(), newId);
} else {
return RestUtils.rename(this.getId(), newId).getResponse();
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class RepositoryAdminResource method touchAllDefinitions.
@POST
@Path("touch")
public Response touchAllDefinitions() {
try {
IRepository repository = RepositoryFactory.getRepository();
SortedSet<DefinitionsChildId> definitionIds = Stream.of(ArtifactTypeId.class, CapabilityTypeId.class, NodeTypeId.class, PolicyTypeId.class, RelationshipTypeId.class, RequirementTypeId.class, ServiceTemplateId.class, DataTypeId.class).flatMap(id -> repository.getAllDefinitionsChildIds(id).stream()).collect(Collectors.toCollection(TreeSet::new));
for (DefinitionsChildId id : definitionIds) {
TDefinitions definitions = repository.getDefinitions(id);
BackendUtils.persist(repository, id, definitions);
}
return Response.ok().build();
} catch (Exception e) {
LOGGER.error("Error touching types: {}", e.getMessage(), e);
return Response.serverError().build();
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class BackendUtils method compare.
public static ToscaDiff compare(DefinitionsChildId id, WineryVersion versionToCompareTo, IRepository repository) {
DefinitionsChildId versionToCompare = VersionSupport.getDefinitionInTheGivenVersion(id, versionToCompareTo);
TExtensibleElements workingVersion = repository.getDefinitions(id).getElement();
TExtensibleElements baseVersion = repository.getDefinitions(versionToCompare).getElement();
return VersionSupport.calculateDifferences(baseVersion, workingVersion);
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RequirementTypeId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>(1);
final TRequirementType element = this.getElement(id);
QName requiredCapabilityType = element.getRequiredCapabilityType();
if (requiredCapabilityType != null) {
CapabilityTypeId capId = new CapabilityTypeId(requiredCapabilityType);
ids.add(capId);
}
return ids;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeId id) {
Collection<NodeTypeImplementationId> allNodeTypeImplementations = this.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, id.getQName());
Collection<DefinitionsChildId> ids = new HashSet<>(allNodeTypeImplementations);
final TNodeType nodeType = this.getElement(id);
// Add all referenced requirement types, but only in XML mode.
// For YAML mode add referenced RelationshipType and CapabilityType, if present
List<TRequirementDefinition> reqDefs = nodeType.getRequirementDefinitions();
if (reqDefs != null) {
for (TRequirementDefinition reqDef : reqDefs) {
// if either of these is set, we're dealing with a type defined in YAML
if (Objects.nonNull(reqDef.getRelationship()) || Objects.nonNull(reqDef.getCapability()) || Objects.nonNull(reqDef.getNode())) {
if (Objects.nonNull(reqDef.getRelationship())) {
ids.add(new RelationshipTypeId(reqDef.getRelationship()));
}
if (Objects.nonNull(reqDef.getCapability())) {
ids.add(new CapabilityTypeId(reqDef.getCapability()));
}
if (Objects.nonNull(reqDef.getNode())) {
ids.add(new NodeTypeId(reqDef.getNode()));
}
} else {
RequirementTypeId reqTypeId = new RequirementTypeId(reqDef.getRequirementType());
ids.add(reqTypeId);
}
}
}
// add all referenced capability types
List<TCapabilityDefinition> capabilityDefinitions = nodeType.getCapabilityDefinitions();
if (capabilityDefinitions != null) {
for (TCapabilityDefinition capDef : capabilityDefinitions) {
CapabilityTypeId capTypeId = new CapabilityTypeId(capDef.getCapabilityType());
ids.add(capTypeId);
// Add all types referenced in valid source types
if (Objects.nonNull(capDef.getValidSourceTypes())) {
capDef.getValidSourceTypes().forEach(sourceType -> ids.add(new NodeTypeId(sourceType)));
}
}
}
List<TInterfaceDefinition> interfaceDefinitions = nodeType.getInterfaceDefinitions();
if (Objects.nonNull(interfaceDefinitions) && !interfaceDefinitions.isEmpty()) {
for (TInterfaceDefinition intDef : interfaceDefinitions) {
InterfaceTypeId interfaceTypeId = new InterfaceTypeId(intDef.getType());
ids.add(interfaceTypeId);
}
}
// Store all referenced artifact types
List<TArtifact> artifacts = nodeType.getArtifacts();
if (Objects.nonNull(artifacts)) {
artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
}
getReferencedDefinitionsOfProperties(ids, nodeType.getProperties());
return ids;
}
Aggregations