use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class RestUtilsWithGitBackendTest method renameAllVersionNamesOfOneComponent.
@Test
public void renameAllVersionNamesOfOneComponent() throws Exception {
this.setRevisionTo("origin/plain");
String version = "_0.3.4-w3";
String oldName = "NodeTypeWith5Versions";
String newName = "exampleName";
String namespace = "http://opentosca.org/nodetypes";
DefinitionsChildId oldId = new NodeTypeId(namespace, oldName + version, false);
DefinitionsChildId newId = new NodeTypeId(namespace, newName + version, false);
Response response = RestUtils.renameAllVersionsOfOneDefinition(oldId, newId);
String expectedEntity = "http://localhost:8080/winery/nodetypes/" + EncodingUtil.URLencode(EncodingUtil.URLencode(namespace)) + "/" + newName + version + "/";
assertEquals(201, response.getStatus());
assertEquals(expectedEntity, response.getEntity());
assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(oldId, repository).size());
assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(newId, repository).size());
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class RestUtilsWithGitBackendTest method getFlagsOfAReleasableVersion.
@Test
public void getFlagsOfAReleasableVersion() throws Exception {
this.setRevisionTo("d920a1a37e3e1c3be32bf282a4d240d83811fdb1");
DefinitionsChildId id = new NodeTypeId("http://plain.winery.opentosca.org/nodetypes", "NodeTypeWithImplementation_1.0-w1-wip1", false);
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(id, repository);
assertTrue(version.isReleasable());
assertTrue(version.isCurrentVersion());
assertTrue(version.isLatestVersion());
assertFalse(version.isEditable());
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class CsarImporter method processDefinitionsImport.
protected Optional<ServiceTemplateId> processDefinitionsImport(TDefinitions defs, TOSCAMetaFile tmf, Path definitionsPath, List<String> errors, CsarImportOptions options) throws IOException {
List<TImport> imports = defs.getImport();
this.importImports(definitionsPath.getParent(), tmf, imports, errors, options);
// imports has been modified to contain necessary imports only
// this method adds new imports to defs which may not be imported using "importImports".
// Therefore, "importTypes" has to be called *after* importImports
this.importTypes(defs, errors);
Optional<ServiceTemplateId> entryServiceTemplate = Optional.empty();
String defaultNamespace = defs.getTargetNamespace();
List<TExtensibleElements> componentInstanceList = defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation();
for (final TExtensibleElements ci : componentInstanceList) {
// Determine namespace
String namespace = this.getNamespace(ci, defaultNamespace);
// Ensure that element has the namespace
this.setNamespace(ci, namespace);
// Determine id
String id = ModelUtilities.getId(ci);
final DefinitionsChildId wid = determineWineryId(ci, namespace, id);
if (targetRepository.exists(wid)) {
if (options.isOverwrite()) {
targetRepository.forceDelete(wid);
String msg = String.format("Deleted %1$s %2$s to enable replacement", ci.getClass().getName(), wid.getQName().toString());
CsarImporter.LOGGER.debug(msg);
} else {
String msg = String.format("Skipped %1$s %2$s, because it already exists", ci.getClass().getName(), wid.getQName().toString());
CsarImporter.LOGGER.debug(msg);
// this is not displayed in the UI as we currently do not distinguish between pre-existing types and types created during the import.
continue;
}
}
// Create a fresh definitions object without the other data.
final TDefinitions newDefs = BackendUtils.createWrapperDefinitions(wid, targetRepository);
// copy over the inputs determined by this.importImports
newDefs.getImport().addAll(imports);
// add the current TExtensibleElements as the only content to it
newDefs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().add(ci);
if (ci instanceof TArtifactTemplate) {
// convention: Definitions are stored in the "Definitions" directory, therefore going to levels up (Definitions dir -> root dir) resolves to the root dir
// COS01, line 2663 states that the path has to be resolved from the *root* of the CSAR
this.adjustArtifactTemplate(definitionsPath.getParent().getParent(), tmf, (ArtifactTemplateId) wid, (TArtifactTemplate) ci, errors);
} else if (ci instanceof TNodeType) {
this.adjustNodeType(definitionsPath.getParent().getParent(), (TNodeType) ci, (NodeTypeId) wid, tmf, errors);
} else if (ci instanceof TRelationshipType) {
this.adjustRelationshipType(definitionsPath.getParent().getParent(), (TRelationshipType) ci, (RelationshipTypeId) wid, tmf, errors);
} else if (ci instanceof TServiceTemplate) {
this.adjustServiceTemplate(definitionsPath.getParent().getParent(), tmf, (ServiceTemplateId) wid, (TServiceTemplate) ci, errors);
entryServiceTemplate = Optional.of((ServiceTemplateId) wid);
}
// import license and readme files
importLicenseAndReadme(definitionsPath.getParent().getParent(), wid, tmf, errors);
// Therefore, we check the entity type separately here
if (ci instanceof TEntityType) {
if (options.isAsyncWPDParsing()) {
// Adjusting takes a long time
// Therefore, we first save the type as is and convert to Winery-Property-Definitions in the background
CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
CsarImporter.entityTypeAdjustmentService.submit(() -> {
adjustEntityType((TEntityType) ci, (EntityTypeId) wid, newDefs, errors);
CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
});
} else {
adjustEntityType((TEntityType) ci, (EntityTypeId) wid, newDefs, errors);
CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
}
} else {
CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
}
}
return entryServiceTemplate;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class CsarImporter method importTypes.
/**
* Imports the specified types into the repository. The types are converted to an import statement
*
* @param errors Container for error messages
*/
private void importTypes(TDefinitions defs, final List<String> errors) {
Types typesContainer = defs.getTypes();
if (typesContainer != null) {
List<Object> types = typesContainer.getAny();
for (Object type : types) {
if (type instanceof Element) {
Element element = (Element) type;
// generate id part of ImportId out of definitions' id
// we do not use the name as the name has to be URLencoded again and we have issues with the interplay with org.eclipse.winery.common.ids.definitions.imports.GenericImportId.getId(TImport) then.
String id = defs.getId();
// try to make the id unique by hashing the "content" of the definition
id = id + "-" + Integer.toHexString(element.hashCode());
// set importId
DefinitionsChildId importId;
String ns;
if (element.getNamespaceURI().equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
ns = element.getAttribute("targetNamespace");
importId = new XSDImportId(ns, id, false);
} else {
// Quick hack for non-XML-Schema-definitions
ns = "unknown";
importId = new GenericImportId(ns, id, false, element.getNamespaceURI());
}
// Following code is adapted from importOtherImports
TDefinitions wrapperDefs = BackendUtils.createWrapperDefinitions(importId, targetRepository);
TImport imp = new TImport();
String fileName = id + ".xsd";
imp.setLocation(fileName);
imp.setImportType(XMLConstants.W3C_XML_SCHEMA_NS_URI);
imp.setNamespace(ns);
wrapperDefs.getImport().add(imp);
CsarImporter.storeDefinitions(targetRepository, importId, wrapperDefs);
// put the file itself to the repo
// ref is required to generate fileRef
RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(importId);
RepositoryFileReference fileRef = new RepositoryFileReference(ref.getParent(), fileName);
// convert element to document
// QUICK HACK. Alternative: Add new method targetRepository.getOutputStream and transform DOM node to OuptputStream
String content = Util.getXMLAsString(element);
try {
targetRepository.putContentToFile(fileRef, content, MediaTypes.MEDIATYPE_TEXT_XML);
} catch (IOException e) {
CsarImporter.LOGGER.debug("Could not put XML Schema definition to file " + fileRef.toString(), e);
errors.add("Could not put XML Schema definition to file " + fileRef.toString());
}
// add import to definitions
// adapt path - similar to importOtherImport
String newLoc = "../" + Util.getUrlPath(fileRef);
imp.setLocation(newLoc);
defs.getImport().add(imp);
} else {
// This is a known type. Otherwise JAX-B would render it as Element
errors.add("There is a Type of class " + type.getClass().toString() + " which is unknown to Winery. The type element is imported as is");
}
}
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class MultiRepository method fixNamespaces.
private void fixNamespaces(IRepository repository) {
SortedSet<DefinitionsChildId> defChildren = repository.getAllDefinitionsChildIds();
Collection<NamespaceProperties> namespaceProperties = new ArrayList<>();
for (DefinitionsChildId value : defChildren) {
namespaceProperties.add(new NamespaceProperties(value.getNamespace().getDecoded(), value.getNamespace().getDecoded().replace(".", ""), "", false));
}
repository.getNamespaceManager().addAllPermanent(namespaceProperties);
}
Aggregations