Search in sources :

Example 1 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class PlanFileResource method getFileRef.

/**
 * Extracts the file reference from plan's planModelReference
 */
@Nullable
private RepositoryFileReference getFileRef() {
    if (this.plan.getPlanModelReference() == null) {
        return null;
    }
    String reference = this.plan.getPlanModelReference().getReference();
    if (reference == null) {
        return null;
    }
    File f = new File(reference);
    return new RepositoryFileReference(this.planId, f.getName());
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) File(java.io.File) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class OptionResource method onDelete.

@Override
public Response onDelete() {
    // delete icon and plan model reference ...
    // delete icon
    // we use the URL stored in the data instead of the generated URL to be compatible with manually edits
    RepositoryFileReference ref = new RepositoryFileReference(this.ssmdId, this.o.getIconUrl());
    try {
        RepositoryFactory.getRepository().forceDelete(ref);
    } catch (IOException e) {
        OptionResource.LOGGER.error("Could not remove file", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
    // delete plan input
    // we use the URL stored in the data instead of the generated URL to be compatible with manually edits
    ref = new RepositoryFileReference(this.ssmdId, this.o.getPlanInputMessageUrl());
    try {
        RepositoryFactory.getRepository().forceDelete(ref);
    } catch (IOException e) {
        OptionResource.LOGGER.error("Could not remove file", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
    // after deleting files, continue with list deletion
    return super.onDelete();
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) IOException(java.io.IOException)

Example 3 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class SelfServicePortalResource method putImage.

@PUT
@Path("image.jpg")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response putImage(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) {
    try {
        SelfServiceMetaDataUtils.ensureDataXmlExists(RepositoryFactory.getRepository(), this.id);
    } catch (IOException e) {
        throw new WebApplicationException(e);
    }
    RepositoryFileReference ref = new RepositoryFileReference(this.id, "image.jpg");
    Response response = RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType());
    if (StringUtils.isEmpty(this.application.getImageUrl())) {
        this.application.setImageUrl("image.jpg");
        persist();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 4 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class CsarImporter method importIcon.

void importIcon(VisualAppearanceId visId, Path visPath, String fileName, TOSCAMetaFile tmf, Path rootPath, final List<String> errors) {
    Path file = visPath.resolve(fileName);
    if (Files.exists(file)) {
        RepositoryFileReference ref = new RepositoryFileReference(visId, fileName);
        importFile(file, ref, tmf, rootPath, errors);
    }
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference)

Example 5 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference 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");
            }
        }
    }
}
Also used : Types(org.eclipse.winery.model.tosca.TDefinitions.Types) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) Element(org.w3c.dom.Element) TImport(org.eclipse.winery.model.tosca.TImport) IOException(java.io.IOException) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) GenericImportId(org.eclipse.winery.model.ids.definitions.imports.GenericImportId)

Aggregations

RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)73 IOException (java.io.IOException)31 Path (java.nio.file.Path)21 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)16 InputStream (java.io.InputStream)13 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)13 ArrayList (java.util.ArrayList)11 QName (javax.xml.namespace.QName)11 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)11 Test (org.junit.jupiter.api.Test)9 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)8 MediaType (org.apache.tika.mime.MediaType)7 BufferedInputStream (java.io.BufferedInputStream)6 HashMap (java.util.HashMap)6 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)6 File (java.io.File)5 Consumes (javax.ws.rs.Consumes)5 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)5 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)5 IRepository (org.eclipse.winery.repository.backend.IRepository)5