Search in sources :

Example 1 with Application

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);
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) Application(org.eclipse.winery.model.selfservice.Application)

Example 2 with Application

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);
            }
        }
    }
}
Also used : Options(org.eclipse.winery.model.selfservice.Application.Options) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) ApplicationOption(org.eclipse.winery.model.selfservice.ApplicationOption) SelfServiceMetaDataId(org.eclipse.winery.repository.datatypes.ids.elements.SelfServiceMetaDataId) Application(org.eclipse.winery.model.selfservice.Application)

Example 3 with Application

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;
}
Also used : TDocumentation(org.eclipse.winery.model.tosca.TDocumentation) Application(org.eclipse.winery.model.selfservice.Application) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Aggregations

Application (org.eclipse.winery.model.selfservice.Application)3 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)2 Options (org.eclipse.winery.model.selfservice.Application.Options)1 ApplicationOption (org.eclipse.winery.model.selfservice.ApplicationOption)1 TDocumentation (org.eclipse.winery.model.tosca.TDocumentation)1 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)1 SelfServiceMetaDataId (org.eclipse.winery.repository.datatypes.ids.elements.SelfServiceMetaDataId)1