Search in sources :

Example 36 with RepositoryFileReference

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;
}
Also used : Path(java.nio.file.Path) Csar(org.opentosca.container.core.model.csar.Csar) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) PlanId(org.eclipse.winery.model.ids.elements.PlanId) XmlId(org.eclipse.winery.model.ids.XmlId) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) PlansId(org.eclipse.winery.model.ids.elements.PlansId) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 37 with RepositoryFileReference

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);
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ApplicationOption(org.eclipse.winery.model.selfservice.ApplicationOption) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation)

Example 38 with RepositoryFileReference

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;
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 39 with RepositoryFileReference

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()));
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 40 with RepositoryFileReference

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);
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) PlanId(org.eclipse.winery.model.ids.elements.PlanId) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) XmlId(org.eclipse.winery.model.ids.XmlId) IOException(java.io.IOException) PlansId(org.eclipse.winery.model.ids.elements.PlansId)

Aggregations

RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)81 IOException (java.io.IOException)33 Path (java.nio.file.Path)26 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)17 QName (javax.xml.namespace.QName)14 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)14 InputStream (java.io.InputStream)13 ArrayList (java.util.ArrayList)12 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)12 IRepository (org.eclipse.winery.repository.backend.IRepository)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 PlanId (org.eclipse.winery.model.ids.elements.PlanId)10 PlansId (org.eclipse.winery.model.ids.elements.PlansId)10 XmlId (org.eclipse.winery.model.ids.XmlId)9 Test (org.junit.jupiter.api.Test)9 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)8 MediaType (org.apache.tika.mime.MediaType)7 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)7 BufferedInputStream (java.io.BufferedInputStream)6 HashMap (java.util.HashMap)6