use of org.eclipse.winery.repository.common.RepositoryFileReference in project container by OpenTOSCA.
the class CamundaPlanEnginePlugin method planLocationOnDisk.
@Nullable
private Path planLocationOnDisk(CsarId csarId, QName planId, PlanModelReference planRef) {
if (storage == null) {
return null;
}
Csar csar = storage.findById(csarId);
IRepository repository = RepositoryFactory.getRepository(csar.getSaveLocation());
PlanId plan = new PlanId(new PlansId(new ServiceTemplateId(csar.entryServiceTemplate().getTargetNamespace(), csar.entryServiceTemplate().getId(), false)), new XmlId(planId.toString(), false));
Collection<RepositoryFileReference> fileRefs = repository.getContainedFiles(plan);
Path planPath = null;
for (RepositoryFileReference ref : fileRefs) {
if (ref.getFileName().endsWith(".war")) {
planPath = repository.ref2AbsolutePath(ref);
break;
}
if (ref.getFileName().endsWith(".zip")) {
planPath = repository.ref2AbsolutePath(ref);
break;
}
}
return planPath;
}
use of org.eclipse.winery.repository.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
RepositoryFileReference iconRef = new RepositoryFileReference(this.selfServiceMetaId, iconFileName);
RestUtils.putContentToFile(iconRef, uploadedInputStream, body.getMediaType());
RepositoryFileReference planInputMessageRef = new RepositoryFileReference(this.selfServiceMetaId, 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.repository.common.RepositoryFileReference in project winery by eclipse.
the class SelfServicePortalResource method putIcon.
@PUT
@Path("icon.jpg")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response putIcon(@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, "icon.jpg");
Response response = RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType());
if (StringUtils.isEmpty(this.application.getIconUrl())) {
this.application.setIconUrl("icon.jpg");
persist();
}
return response;
}
use of org.eclipse.winery.repository.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 Response onPutFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body) {
String fileName = fileDetail.getFileName();
RepositoryFileReference ref = new RepositoryFileReference(this.planId, fileName);
RepositoryFileReference oldRef = this.getFileRef();
// if oldRef exists -> check for equality and afterwards overwrite the old content
if (oldRef != null && !ref.equals(oldRef)) {
// new filename sent
RestUtils.delete(oldRef);
}
PlansResource.setPlanModelReference(this.plan, this.planId, fileName);
RestUtils.persist(this.res);
return RestUtils.putContentToFile(ref, uploadedInputStream, org.apache.tika.mime.MediaType.parse(body.getMediaType().toString()));
}
use of org.eclipse.winery.repository.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, "{}", MediaType.APPLICATION_JSON_TYPE);
} 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 = EncodingUtil.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);
}
Aggregations