use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class YamlRepository method getRequestedDefinition.
/**
* Parses only requested Definition from converted yaml service template
*
* @param id Definitions Child id
* @param definitions converted definitions
* @return requested definitions
*/
private TDefinitions getRequestedDefinition(DefinitionsChildId id, TDefinitions definitions) {
if (id instanceof ArtifactTemplateId) {
String artifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
List<TArtifactTemplate> artifactTemplates = definitions.getArtifactTemplates();
List<TArtifactTemplate> requestedArtifactTemplates = new ArrayList<>();
for (TArtifactTemplate artifactTemplate : artifactTemplates) {
if (artifactTemplate.getId().equalsIgnoreCase(artifactName)) {
requestedArtifactTemplates.add(artifactTemplate);
TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
requestedDefinitions.addArtifactTemplates(requestedArtifactTemplates);
return requestedDefinitions.build();
}
}
// we did not find the artifact template id (this should not happen!)
LOGGER.error("requested artifact template id (" + id.toReadableString() + ") cannot be extracted from definitions object!");
return definitions;
} else {
TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
if (id instanceof NodeTypeId) {
requestedDefinitions.addNodeTypes(definitions.getNodeTypes());
} else if (id instanceof RelationshipTypeId) {
requestedDefinitions.addRelationshipTypes(definitions.getRelationshipTypes());
} else if (id instanceof NodeTypeImplementationId) {
requestedDefinitions.addNodeTypeImplementations(definitions.getNodeTypeImplementations());
} else if (id instanceof RelationshipTypeImplementationId) {
requestedDefinitions.addRelationshipTypeImplementations(definitions.getRelationshipTypeImplementations());
} else if (id instanceof ArtifactTypeId) {
requestedDefinitions.addArtifactTypes(definitions.getArtifactTypes());
} else if (id instanceof CapabilityTypeId) {
requestedDefinitions.addCapabilityTypes(definitions.getCapabilityTypes());
} else if (id instanceof DataTypeId) {
requestedDefinitions.addDataTypes(definitions.getDataTypes());
} else if (id instanceof RequirementTypeId) {
requestedDefinitions.addRequirementTypes(definitions.getRequirementTypes());
} else if (id instanceof PolicyTypeId) {
requestedDefinitions.addPolicyTypes(definitions.getPolicyTypes());
} else if (id instanceof InterfaceTypeId) {
requestedDefinitions.addInterfaceTypes(definitions.getInterfaceTypes());
} else {
// we do not need to filter anything
return definitions;
}
return requestedDefinitions.build();
}
}
use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class YamlRepository method convertGenericId.
/**
* Converts Generic id of non existing XML Definitions in compatible YAML Definition
*
* @param id GenericId
* @return converted Generic Id
*/
private GenericId convertGenericId(GenericId id) {
if (id instanceof NodeTypeImplementationId) {
return new NodeTypeId(((NodeTypeImplementationId) id).getQName());
} else if (id instanceof RelationshipTypeImplementationId) {
return new RelationshipTypeId(((RelationshipTypeImplementationId) id).getQName());
} else if (id instanceof ArtifactTemplateId) {
QName qName = ((ArtifactTemplateId) id).getQName();
Matcher nameMatcher = namePattern.matcher(qName.getLocalPart());
if (nameMatcher.matches()) {
String typeName = nameMatcher.group(2);
if (nameMatcher.group(3).equalsIgnoreCase("nodetypes")) {
return new NodeTypeId(new QName(qName.getNamespaceURI(), typeName));
} else {
return new RelationshipTypeId(new QName(qName.getNamespaceURI(), typeName));
}
} else {
return new NodeTypeId(new QName(qName.getNamespaceURI(), "Cache"));
}
}
return null;
}
use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class TestWineryRepositoryClient method createArtifactTemplate.
@Test
public void createArtifactTemplate() throws Exception {
this.setRevisionTo("origin/plain");
// assure that the artifact type exists
QName artifactTypeQName = TestWineryRepositoryClient.client.getArtifactTypeQNameForExtension("war");
assertNotNull(artifactTypeQName, "Artifact Type for .war does not exist");
// assure that the artifact template does not yet exist
// one possibility is to delete the artifact template, the other
// possibility is to
QName artifactTemplateQName = new QName(TestWineryRepositoryClient.NAMESPACE_FOR_NEW_ARTIFACTS, "artifactTemplate");
ArtifactTemplateId atId = new ArtifactTemplateId(artifactTemplateQName);
// ensure that the template does not exist yet
TestWineryRepositoryClient.client.forceDelete(atId);
TestWineryRepositoryClient.client.createArtifactTemplate(artifactTemplateQName, artifactTypeQName);
}
use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class RestUtils method create.
/**
* Generates given TOSCA element and returns appropriate response code <br />
* <p>
* In the case of an existing resource, the other possible return code is 302. This code has no Status constant,
* therefore we use Status.CONFLICT, which is also possible.
*
* @return <ul> <li> <ul> <li>Status.CREATED (201) if the resource has been created,</li> <li>Status.CONFLICT if the
* resource already exists,</li> <li>Status.INTERNAL_SERVER_ERROR (500) if something went wrong</li> </ul> </li>
* <li>URI: the absolute URI of the newly created resource</li> </ul>
*/
public static ResourceResult create(GenericId id, String name) {
ResourceResult res = new ResourceResult();
if (RepositoryFactory.getRepository().exists(id)) {
// res.setStatus(302);
res.setStatus(Status.CONFLICT);
} else {
if (RepositoryFactory.getRepository().flagAsExisting(id)) {
res.setStatus(Status.CREATED);
// @formatter:off
// This method is a generic method
// We cannot return an "absolute" URL as the URL is always
// relative to the caller
// Does not work: String path = Environment.getUrlConfiguration().getRepositoryApiUrl()
// + "/" +
// Utils.getUrlPathForPathInsideRepo(id.getPathInsideRepo());
// We distinguish between two cases: DefinitionsChildId and
// TOSCAelementId
// @formatter:on
String path;
if (id instanceof DefinitionsChildId) {
// here, we return namespace + id, as it is only possible to
// post on the definition child*s* resource to create an
// instance of a definition child
DefinitionsChildId tcId = (DefinitionsChildId) id;
path = tcId.getNamespace().getEncoded() + "/" + tcId.getXmlId().getEncoded() + "/";
// in case the resource additionally supports a name attribute, we set the original name
if ((tcId instanceof ServiceTemplateId) || (tcId instanceof ArtifactTemplateId) || (tcId instanceof PolicyTemplateId)) {
// these three types have an additional name (instead of a pure id)
// we store the name
IHasName resource = (IHasName) AbstractComponentsResource.getComponentInstanceResource(tcId);
resource.setName(name);
}
} else {
assert (id instanceof ToscaElementId);
// We just return the id as we assume that only the parent
// of this id may create sub elements
path = id.getXmlId().getEncoded() + "/";
}
// we have to encode it twice to get correct URIs
path = Util.getUrlPath(path);
URI uri = URI.create(path);
res.setUri(uri);
res.setId(id);
} else {
res.setStatus(Status.INTERNAL_SERVER_ERROR);
}
}
return res;
}
use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class BackendUtilsTest method repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated.
@Test
public void repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated() {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "file.txt"), artifactTemplateSourceDirectoryId);
assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
assertEquals(Optional.empty(), repositoryFileReference.getSubDirectory());
assertEquals("file.txt", repositoryFileReference.getFileName());
}
Aggregations