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