Search in sources :

Example 1 with GenericId

use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.

the class YamlRepository method exists.

/**
 * Checks if YAML Definition exists Artifact Templates are searched in Type
 *
 * @param id generic id of target
 * @return boolean if target exists
 */
@Override
public boolean exists(GenericId id) {
    Path targetPath = id2AbsolutePath(id);
    if (id instanceof ArtifactTemplateId) {
        GenericId convertedId = convertGenericId(id);
        if (convertedId != null) {
            String convertedFilename = BackendUtils.getFileNameOfDefinitions((DefinitionsChildId) convertedId);
            targetPath = targetPath.resolve(convertedFilename);
            return artifactTemplateExistsInType(targetPath, ((ArtifactTemplateId) id).getQName());
        }
    }
    return Files.exists(targetPath);
}
Also used : Path(java.nio.file.Path) GenericId(org.eclipse.winery.model.ids.GenericId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)

Example 2 with GenericId

use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.

the class YamlRepository method ref2AbsolutePath.

/**
 * Converts RepositoryFileReference to compatible YAML File
 *
 * @param ref RepositoryFileReference
 * @return compatible Path
 */
@Override
public Path ref2AbsolutePath(RepositoryFileReference ref) {
    Path resultPath = super.ref2AbsolutePath(ref);
    GenericId convertedId = convertGenericId(ref.getParent());
    if (convertedId != null) {
        if (convertedId instanceof DefinitionsChildId) {
            String convertedFilename = BackendUtils.getFileNameOfDefinitions((DefinitionsChildId) convertedId);
            return resultPath.resolve(convertedFilename);
        }
    }
    return resultPath;
}
Also used : Path(java.nio.file.Path) GenericId(org.eclipse.winery.model.ids.GenericId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId)

Example 3 with GenericId

use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.

the class AbstractFileBasedRepository method getContainedFiles.

@Override
public SortedSet<RepositoryFileReference> getContainedFiles(GenericId id) {
    Path dir = this.id2AbsolutePath(id);
    SortedSet<RepositoryFileReference> res = new TreeSet<>();
    if (!Files.exists(dir)) {
        return res;
    }
    assert (Files.isDirectory(dir));
    final OnlyNonHiddenFiles onlyNonHiddenFiles = new OnlyNonHiddenFiles();
    try {
        Files.walk(dir).filter(f -> {
            try {
                return onlyNonHiddenFiles.accept(f);
            } catch (IOException e) {
                LOGGER.debug("Error during crawling", e);
                return false;
            }
        }).map(f -> {
            final Path relativePath = dir.relativize(f.getParent());
            if (relativePath.toString().isEmpty()) {
                return new RepositoryFileReference(id, f.getFileName().toString());
            } else {
                return new RepositoryFileReference(id, relativePath, f.getFileName().toString());
            }
        }).forEach(res::add);
    } catch (IOException e1) {
        LOGGER.debug("Error during crawling", e1);
    }
    return res;
}
Also used : Path(java.nio.file.Path) ConfigurationEvent(org.apache.commons.configuration2.event.ConfigurationEvent) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) NoSuchFileException(java.nio.file.NoSuchFileException) SortedSet(java.util.SortedSet) IdUtil(org.eclipse.winery.model.ids.IdUtil) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) FileTime(java.nio.file.attribute.FileTime) InvalidPathException(org.eclipse.jgit.dircache.InvalidPathException) Namespace(org.eclipse.winery.model.ids.Namespace) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException) DirectoryStream(java.nio.file.DirectoryStream) GenericId(org.eclipse.winery.model.ids.GenericId) Util(org.eclipse.winery.repository.common.Util) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Collection(java.util.Collection) Constants(org.eclipse.winery.common.Constants) Reader(java.io.Reader) FileSystem(java.nio.file.FileSystem) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Objects(java.util.Objects) FileVisitResult(java.nio.file.FileVisitResult) IOUtils(org.apache.commons.io.IOUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) Optional(java.util.Optional) ZipOutputStream(java.util.zip.ZipOutputStream) ZipInputStream(java.util.zip.ZipInputStream) FileSystemProvider(java.nio.file.spi.FileSystemProvider) MediaType(org.apache.tika.mime.MediaType) Constructor(java.lang.reflect.Constructor) TreeSet(java.util.TreeSet) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Charset(java.nio.charset.Charset) XmlId(org.eclipse.winery.model.ids.XmlId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) Configuration(org.apache.commons.configuration2.Configuration) ToscaElementId(org.eclipse.winery.model.ids.elements.ToscaElementId) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) InputStream(java.io.InputStream) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) TreeSet(java.util.TreeSet) IOException(java.io.IOException)

Example 4 with GenericId

use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.

the class YamlRepository method deleteArtifact.

/**
 * Deletes artifacts from there referenced type
 *
 * @param id Artifact Template id
 */
private void deleteArtifact(ArtifactTemplateId id) {
    if (getNameOfTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("Cache")) {
        super.forceDelete(id);
    } else {
        Path targetPath = id2AbsolutePath(id);
        GenericId convertedId = convertGenericId(id);
        if (convertedId != null) {
            if (convertedId instanceof DefinitionsChildId) {
                String convertedFilename = BackendUtils.getFileNameOfDefinitions((DefinitionsChildId) convertedId);
                targetPath = targetPath.resolve(convertedFilename);
            }
        }
        if (Files.exists(targetPath)) {
            try {
                YTServiceTemplate nodeType = readServiceTemplate(targetPath);
                String targetArtifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
                if (getTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("nodetypes")) {
                    Map<String, YTArtifactDefinition> artifacts = nodeType.getNodeTypes().entrySet().iterator().next().getValue().getArtifacts();
                    nodeType.getNodeTypes().entrySet().iterator().next().setValue(removeImplementation(nodeType.getNodeTypes().entrySet().iterator().next().getValue(), targetArtifactName));
                    artifacts.remove(targetArtifactName);
                    nodeType.getNodeTypes().entrySet().iterator().next().getValue().setArtifacts(artifacts);
                } else {
                    nodeType.getRelationshipTypes().entrySet().iterator().next().setValue(removeRelationshipArtifact(nodeType.getRelationshipTypes().entrySet().iterator().next().getValue(), targetArtifactName));
                }
                YamlWriter writer = new YamlWriter();
                InputStream output = writer.writeToInputStream(nodeType);
                writeInputStreamToPath(targetPath, output);
            } catch (Exception e) {
                LOGGER.error("Error deleting file: {}", e.getMessage(), e);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) GenericId(org.eclipse.winery.model.ids.GenericId) YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) IOException(java.io.IOException) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 5 with GenericId

use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.

the class RestUtils method getZippedContents.

/**
 * Zips the folder reference given by the id. As filename the parent id is used.
 *
 * @param id   the id of the folder
 * @param name the name of the result zip (including.zip)
 */
public static Response getZippedContents(final GenericId id, String name) {
    StreamingOutput so = output -> {
        try {
            RepositoryFactory.getRepository().getZippedContents(id, output);
        } catch (Exception e) {
            throw new WebApplicationException(e);
        }
    };
    String sb = "attachment;filename=\"" + name + "\"";
    return Response.ok().header("Content-Disposition", sb).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
Also used : MimeTypes(org.eclipse.winery.common.constants.MimeTypes) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) FileTime(java.nio.file.attribute.FileTime) HasType(org.eclipse.winery.model.tosca.HasType) CsarExportConfiguration(org.eclipse.winery.repository.export.CsarExportConfiguration) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) WineryVersion(org.eclipse.winery.common.version.WineryVersion) MediaType(javax.ws.rs.core.MediaType) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) Duration(java.time.Duration) Map(java.util.Map) GenericId(org.eclipse.winery.model.ids.GenericId) QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) WineryVersionUtils(org.eclipse.winery.repository.backend.WineryVersionUtils) EdmmManager(org.eclipse.winery.edmm.EdmmManager) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) Constants(org.eclipse.winery.common.Constants) Set(java.util.Set) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CsarExportOptions(org.eclipse.winery.repository.export.CsarExportOptions) VersionUtils(org.eclipse.winery.common.version.VersionUtils) WebApplicationException(javax.ws.rs.WebApplicationException) LocalNameForAngular(org.eclipse.winery.repository.rest.datatypes.LocalNameForAngular) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) EdmmType(org.eclipse.winery.edmm.model.EdmmType) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) XmlId(org.eclipse.winery.model.ids.XmlId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Family(javax.ws.rs.core.Response.Status.Family) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) UiConfigurationObject(org.eclipse.winery.common.configuration.UiConfigurationObject) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) SortedSet(java.util.SortedSet) Date(java.util.Date) EdmmConverter(org.eclipse.winery.edmm.model.EdmmConverter) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) ContentDisposition(org.glassfish.jersey.media.multipart.ContentDisposition) NamespaceAndDefinedLocalNamesForAngular(org.eclipse.winery.repository.rest.datatypes.NamespaceAndDefinedLocalNamesForAngular) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) SelfContainmentPackager(org.eclipse.winery.repository.backend.selfcontainmentpackager.SelfContainmentPackager) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Locale(java.util.Locale) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) Util(org.eclipse.winery.repository.common.Util) URI(java.net.URI) QNameConverter(org.eclipse.winery.repository.rest.resources.apiData.converter.QNameConverter) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Collection(java.util.Collection) StreamingOutput(javax.ws.rs.core.StreamingOutput) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) Objects(java.util.Objects) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) List(java.util.List) NamespaceAndDefinedLocalNames(org.eclipse.winery.repository.backend.xsd.NamespaceAndDefinedLocalNames) HttpHeaders(javax.ws.rs.core.HttpHeaders) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) YamlExporter(org.eclipse.winery.repository.yaml.export.YamlExporter) Response(javax.ws.rs.core.Response) IRepository(org.eclipse.winery.repository.backend.IRepository) AccessControlException(java.security.AccessControlException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) Marshaller(javax.xml.bind.Marshaller) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ClientBuilder(javax.ws.rs.client.ClientBuilder) TConstraint(org.eclipse.winery.model.tosca.TConstraint) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Application(org.eclipse.winery.model.selfservice.Application) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) Logger(org.slf4j.Logger) Environments(org.eclipse.winery.common.configuration.Environments) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource) TTag(org.eclipse.winery.model.tosca.TTag) ToscaElementId(org.eclipse.winery.model.ids.elements.ToscaElementId) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) EntityGraph(io.github.edmm.core.parser.EntityGraph) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) ComponentId(org.eclipse.winery.repository.rest.datatypes.ComponentId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) AbstractComponentsResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource) InputStream(java.io.InputStream) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IHasName(org.eclipse.winery.repository.rest.resources._support.IHasName) WebApplicationException(javax.ws.rs.WebApplicationException) StreamingOutput(javax.ws.rs.core.StreamingOutput) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) AccessControlException(java.security.AccessControlException)

Aggregations

GenericId (org.eclipse.winery.model.ids.GenericId)5 Path (java.nio.file.Path)4 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 FileTime (java.nio.file.attribute.FileTime)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Objects (java.util.Objects)2 SortedSet (java.util.SortedSet)2 JAXBException (javax.xml.bind.JAXBException)2 Constants (org.eclipse.winery.common.Constants)2 Namespace (org.eclipse.winery.model.ids.Namespace)2 XmlId (org.eclipse.winery.model.ids.XmlId)2 ToscaElementId (org.eclipse.winery.model.ids.elements.ToscaElementId)2 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)2 BackendUtils (org.eclipse.winery.repository.backend.BackendUtils)2