Search in sources :

Example 11 with RepositoryFileReference

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

the class ToscaExportUtil method prepareForExport.

/**
 * Synchronizes the plan model references and adds the plans to the csar (putRefAsReferencedItemInCsar)
 */
private void prepareForExport(IRepository repository, ServiceTemplateId id) throws IOException {
    // ensure that the plans stored locally are the same ones as stored in the definitions
    BackendUtils.synchronizeReferences(id);
    // add all plans as reference in the CSAR
    // the data model is consistent with the repository
    // we crawl through the repository to as putRefAsReferencedItemInCsar expects a repository file reference
    PlansId plansContainerId = new PlansId(id);
    SortedSet<PlanId> nestedPlans = repository.getNestedIds(plansContainerId, PlanId.class);
    for (PlanId planId : nestedPlans) {
        SortedSet<RepositoryFileReference> containedFiles = repository.getContainedFiles(planId);
        // even if we currently support only one file in the directory, we just add everything
        for (RepositoryFileReference ref : containedFiles) {
            this.putRefAsReferencedItemInCsar(ref);
        }
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) PlanId(org.eclipse.winery.common.ids.elements.PlanId) PlansId(org.eclipse.winery.common.ids.elements.PlansId)

Example 12 with RepositoryFileReference

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

the class CsarImporter method importIcon.

private 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 : RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference)

Example 13 with RepositoryFileReference

use of org.eclipse.winery.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);
                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(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 RepositoryFactory.getRepository().getOutputStream and transform DOM node to OuptputStream
                String content = Util.getXMLAsString(element);
                try {
                    RepositoryFactory.getRepository().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.common.ids.definitions.imports.XSDImportId) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) Element(org.w3c.dom.Element) IOException(java.io.IOException) GenericImportId(org.eclipse.winery.common.ids.definitions.imports.GenericImportId)

Example 14 with RepositoryFileReference

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

the class PlanFileResource method getFileRef.

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

Example 15 with RepositoryFileReference

use of org.eclipse.winery.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.common.RepositoryFileReference) IOException(java.io.IOException)

Aggregations

RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)51 IOException (java.io.IOException)15 InputStream (java.io.InputStream)8 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)8 Definitions (org.eclipse.winery.model.tosca.Definitions)8 BufferedInputStream (java.io.BufferedInputStream)6 ArtifactTemplateSourceDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId)6 Test (org.junit.Test)6 Path (java.nio.file.Path)5 JAXBException (javax.xml.bind.JAXBException)5 MediaType (org.apache.tika.mime.MediaType)5 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)5 ZipInputStream (java.util.zip.ZipInputStream)4 Unmarshaller (javax.xml.bind.Unmarshaller)4 QName (javax.xml.namespace.QName)4 XmlId (org.eclipse.winery.common.ids.XmlId)4 GenericImportId (org.eclipse.winery.common.ids.definitions.imports.GenericImportId)4 XSDImportId (org.eclipse.winery.common.ids.definitions.imports.XSDImportId)4 PlanId (org.eclipse.winery.common.ids.elements.PlanId)4 PlansId (org.eclipse.winery.common.ids.elements.PlansId)4