use of org.eclipse.winery.model.selfservice.ApplicationOption in project winery by eclipse.
the class CsarExporter method addSelfServiceMetaData.
/**
* Adds all self service meta data to the targetDir
*
* @param targetDir the directory in the CSAR where to put the content to
* @param refMap is used later to create the CSAR
*/
private void addSelfServiceMetaData(IRepository repository, ServiceTemplateId entryId, String targetDir, Map<RepositoryFileReference, String> refMap) throws IOException {
final SelfServiceMetaDataId selfServiceMetaDataId = new SelfServiceMetaDataId(entryId);
// This method is also called if the directory SELFSERVICE-Metadata exists without content and even if the directory does not exist at all,
// but the ServiceTemplate itself exists.
// The current assumption is that this is enough for an existence.
// Thus, we have to take care of the case of an empty directory and add a default data.xml
SelfServiceMetaDataUtils.ensureDataXmlExists(selfServiceMetaDataId);
refMap.put(SelfServiceMetaDataUtils.getDataXmlRef(selfServiceMetaDataId), targetDir + "data.xml");
// The schema says that the images have to exist
// However, at a quick modeling, there might be no images
// Therefore, we check for existence
final RepositoryFileReference iconJpgRef = SelfServiceMetaDataUtils.getIconJpgRef(selfServiceMetaDataId);
if (repository.exists(iconJpgRef)) {
refMap.put(iconJpgRef, targetDir + "icon.jpg");
}
final RepositoryFileReference imageJpgRef = SelfServiceMetaDataUtils.getImageJpgRef(selfServiceMetaDataId);
if (repository.exists(imageJpgRef)) {
refMap.put(imageJpgRef, targetDir + "image.jpg");
}
Application application = SelfServiceMetaDataUtils.getApplication(selfServiceMetaDataId);
// clear CSAR name as this may change.
application.setCsarName(null);
// hack for the OpenTOSCA container to display something
application.setVersion("1.0");
List<String> authors = application.getAuthors();
if (authors.isEmpty()) {
authors.add("Winery");
}
// make the patches to data.xml permanent
try {
BackendUtils.persist(application, SelfServiceMetaDataUtils.getDataXmlRef(selfServiceMetaDataId), MediaTypes.MEDIATYPE_TEXT_XML);
} catch (IOException e) {
LOGGER.error("Could not persist patches to data.xml", e);
}
Options options = application.getOptions();
if (options != null) {
SelfServiceMetaDataId id = new SelfServiceMetaDataId(entryId);
for (ApplicationOption option : options.getOption()) {
String url = option.getIconUrl();
if (Util.isRelativeURI(url)) {
putRefIntoRefMap(targetDir, refMap, repository, id, url);
}
url = option.getPlanInputMessageUrl();
if (Util.isRelativeURI(url)) {
putRefIntoRefMap(targetDir, refMap, repository, id, url);
}
}
}
}
use of org.eclipse.winery.model.selfservice.ApplicationOption 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);
}
Aggregations