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);
}
}
}
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);
}
}
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");
}
}
}
}
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());
}
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();
}
Aggregations