use of org.eclipse.winery.common.RepositoryFileReference in project winery by eclipse.
the class XSDImportResource method getXSD.
@GET
@ApiOperation(value = "May be used by the modeler to generate an XML editor based on the XML schema")
// we cannot use "MimeTypes.MIMETYPE_XSD" here as the latter is "text/xml" and org.eclipse.winery.repository.resources.AbstractComponentInstanceResource.getDefinitionsAsResponse() also produces text/xml
@Produces("text/xsd")
public Response getXSD() {
final Optional<String> location = ImportUtils.getLocation((GenericImportId) id);
if (!location.isPresent()) {
return Response.status(Status.NOT_FOUND).build();
}
RepositoryFileReference ref = new RepositoryFileReference(this.id, location.get());
return RestUtils.returnRepoPath(ref, null);
}
use of org.eclipse.winery.common.RepositoryFileReference in project winery by eclipse.
the class PlanFileResource method onPutFile.
@PUT
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@ApiOperation(value = "Resource currently works for BPMN4TOSCA plans only")
public // @formatter:off
Response onPutFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body) {
// @formatter:on
String fileName = fileDetail.getFileName();
RepositoryFileReference ref = new RepositoryFileReference(this.planId, fileName);
RepositoryFileReference oldRef = this.getFileRef();
boolean persistanceNecessary;
if (ref.equals(oldRef)) {
// nothing todo, file will be replaced
persistanceNecessary = false;
} else {
// new filename sent
RestUtils.delete(oldRef);
PlansResource.setPlanModelReference(this.plan, this.planId, fileName);
persistanceNecessary = true;
}
// Really store it
try {
RepositoryFactory.getRepository().putContentToFile(ref, uploadedInputStream, org.apache.tika.mime.MediaType.parse(body.getMediaType().toString()));
} catch (IOException e1) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Could not store plan. " + e1.getMessage()).build();
}
if (persistanceNecessary) {
return RestUtils.persist(this.res);
} else {
return Response.noContent().build();
}
}
use of org.eclipse.winery.common.RepositoryFileReference in project winery by eclipse.
the class PlansResource method saveFile.
private Response saveFile(TPlan tPlan, InputStream uploadedInputStream, FormDataContentDisposition fileDetail, FormDataBodyPart body) {
boolean bpmn4toscaMode = Namespaces.URI_BPMN4TOSCA_20.equals(tPlan.getPlanLanguage());
if (uploadedInputStream != null || bpmn4toscaMode) {
// Determine Id
PlansId plansId = new PlansId((ServiceTemplateId) ((ServiceTemplateResource) this.res).getId());
PlanId planId = new PlanId(plansId, new XmlId(tPlan.getId(), false));
// Ensure overwriting
if (RepositoryFactory.getRepository().exists(planId)) {
try {
RepositoryFactory.getRepository().forceDelete(planId);
// Quick hack to remove the deleted plan from the plans element
((ServiceTemplateResource) this.res).synchronizeReferences();
} catch (IOException e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
String fileName;
if (bpmn4toscaMode) {
fileName = tPlan.getId() + Constants.SUFFIX_BPMN4TOSCA;
RepositoryFileReference ref = new RepositoryFileReference(planId, fileName);
// Errors are ignored in the following call
RestUtils.putContentToFile(ref, "{}", MediaTypes.MEDIATYPE_APPLICATION_JSON);
} else {
// We use the filename also as local file name. Alternatively, we could use the xml id
// With URL encoding, this should not be an issue
fileName = Util.URLencode(fileDetail.getFileName());
// Really store it
RepositoryFileReference ref = new RepositoryFileReference(planId, fileName);
// Errors are ignored in the following call
RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType());
}
PlansResource.setPlanModelReference(tPlan, planId, fileName);
}
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.common.RepositoryFileReference in project winery by eclipse.
the class OptionsResource method onPost.
@POST
@ApiOperation(value = "Adds a new option<p>TODO: @return JSON with .tableData: Array with row data for dataTable</p>")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public // @formatter:off
Response onPost(@FormDataParam("name") String name, @FormDataParam("description") String description, @FormDataParam("planServiceName") String planServiceName, @FormDataParam("planInputMessage") String planInputMessage, @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body) {
// @formatter:on
if (StringUtils.isEmpty(name)) {
return Response.status(Status.BAD_REQUEST).entity("planName must be given").build();
}
if (StringUtils.isEmpty(description)) {
return Response.status(Status.BAD_REQUEST).entity("description must be given").build();
}
if (StringUtils.isEmpty(planServiceName)) {
return Response.status(Status.BAD_REQUEST).entity("planServiceName must be given").build();
}
if (StringUtils.isEmpty(planInputMessage)) {
return Response.status(Status.BAD_REQUEST).entity("planInputMessage must be given").build();
}
if (uploadedInputStream == null) {
return Response.status(Status.BAD_REQUEST).entity("file has to be provided").build();
}
ApplicationOption option = new ApplicationOption();
String id = RestUtils.createXMLidAsString(name);
String fileNamePrefix = OptionResource.getFileNamePrefix(id);
String iconFileName = fileNamePrefix + OptionResource.ICON_JPG;
String planInputMessageFileName = fileNamePrefix + OptionResource.PLAN_INPUT_XML;
// create option data
option.setId(id);
option.setName(name);
option.setDescription(description);
option.setIconUrl(iconFileName);
option.setPlanInputMessageUrl(planInputMessageFileName);
option.setPlanServiceName(planServiceName);
// BEGIN: store icon and planInputMessage
SelfServiceMetaDataId ssmdId = ((SelfServicePortalResource) this.res).getId();
RepositoryFileReference iconRef = new RepositoryFileReference(ssmdId, iconFileName);
RestUtils.putContentToFile(iconRef, uploadedInputStream, body.getMediaType());
RepositoryFileReference planInputMessageRef = new RepositoryFileReference(ssmdId, planInputMessageFileName);
RestUtils.putContentToFile(planInputMessageRef, planInputMessage, MediaType.TEXT_XML_TYPE);
// END: store icon and planInputMessage
this.list.add(option);
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.common.RepositoryFileReference in project winery by eclipse.
the class BackendUtilsTest method repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated.
@Test
public void repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated() {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "file.txt"), artifactTemplateSourceDirectoryId);
Assert.assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
Assert.assertEquals(Optional.empty(), repositoryFileReference.getSubDirectory());
Assert.assertEquals("file.txt", repositoryFileReference.getFileName());
}
Aggregations