use of org.eclipse.winery.model.selfservice.Application in project winery by eclipse.
the class SelfServiceMetaDataUtils method ensureDataXmlExists.
public static void ensureDataXmlExists(SelfServiceMetaDataId id) throws IOException {
RepositoryFileReference data_xml_ref = getDataXmlRef(id);
if (!RepositoryFactory.getRepository().exists(data_xml_ref)) {
final Application application = new Application();
BackendUtils.persist(application, data_xml_ref, MediaTypes.MEDIATYPE_TEXT_XML);
}
}
use of org.eclipse.winery.model.selfservice.Application 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.Application in project winery by eclipse.
the class SelfServiceMetaDataUtils method getDefaultApplicationData.
private static Application getDefaultApplicationData(SelfServiceMetaDataId id) {
Application app = new Application();
app.setIconUrl("icon.jpg");
app.setImageUrl("image.jpg");
final TServiceTemplate serviceTemplate = RepositoryFactory.getRepository().getElement((ServiceTemplateId) id.getParent());
app.setDisplayName(serviceTemplate.getName());
List<TDocumentation> documentation = serviceTemplate.getDocumentation();
if ((documentation != null) && (!documentation.isEmpty())) {
TDocumentation doc = documentation.get(0);
List<Object> content = doc.getContent();
if ((content != null) && (!content.isEmpty())) {
app.setDescription(content.get(0).toString());
}
}
return app;
}
Aggregations