use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class MultiRepository method addNamespacesToRepository.
private void addNamespacesToRepository(IRepository repository, GenericId id) {
if (id instanceof DefinitionsChildId) {
Namespace namespace = ((DefinitionsChildId) id).getNamespace();
String ns = namespace.getDecoded();
IRepository r = determineRepositoryRef(repository);
Set<String> set = repositoryGlobal.get(r);
set.add(ns);
repositoryGlobal.put(r, set);
String pns;
try {
if (this.localRepository.getRepository() instanceof XmlRepository) {
pns = namespace.getEncoded().substring(0, namespace.getEncoded().lastIndexOf(RepositoryUtils.getUrlSeparatorEncoded()));
} else {
pns = namespace.getEncoded();
}
} catch (UnsupportedEncodingException ex) {
LOGGER.error("Error when generating the namespace", ex);
return;
}
Set<Namespace> setPre = repositoryCommonNamespace.get(r);
setPre.add(new Namespace(pns, true));
repositoryCommonNamespace.put(r, setPre);
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class TemplatesOfOneType method getJSON.
/**
* returns a list of all implementations of a type using the getAllImplementations method
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getJSON() {
Collection<? extends DefinitionsChildId> allImplementations = this.getAllImplementations();
List<QNameApiData> res = new ArrayList<>(allImplementations.size());
QNameConverter adapter = new QNameConverter();
for (DefinitionsChildId id : allImplementations) {
res.add(adapter.marshal(id.getQName()));
}
return Response.ok().entity(res).build();
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class CsarExporter method writeSelfContainedCsar.
public void writeSelfContainedCsar(IRepository repository, DefinitionsChildId entryId, OutputStream output, Map<String, Object> exportConfiguration) throws IOException, RepositoryCorruptException, InterruptedException, AccountabilityException, ExecutionException {
SelfContainmentPackager selfContainmentPackager = new SelfContainmentPackager(repository);
DefinitionsChildId newServiceTemplateId = selfContainmentPackager.createSelfContainedVersion(entryId);
exportConfiguration.put(CsarExportConfiguration.INCLUDE_DEPENDENCIES.name(), true);
this.writeCsar(newServiceTemplateId, output, exportConfiguration);
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class CsarExporter method addManifest.
private String addManifest(DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
String entryDefinitionsReference = CsarExporter.getDefinitionsPathInsideCSAR(repository, id);
out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
StringBuilder stringBuilder = new StringBuilder();
// Setting Versions
stringBuilder.append(TOSCA_META_VERSION).append(": 1.0").append("\n");
stringBuilder.append(CSAR_VERSION).append(": 1.0").append("\n");
stringBuilder.append(CREATED_BY).append(": Winery ").append(Environments.getInstance().getVersion()).append("\n");
// Winery currently is unaware of tDefinitions, therefore, we use the
// name of the service template
stringBuilder.append(ENTRY_DEFINITIONS).append(": ").append(entryDefinitionsReference).append("\n");
stringBuilder.append("\n");
assert (refMap.keySet().stream().anyMatch(fileProperties -> fileProperties.getPathInsideCsar().equals(entryDefinitionsReference)));
// Setting other files, mainly files belonging to artifacts
for (Map.Entry<CsarContentProperties, CsarEntry> item : refMap.entrySet()) {
final CsarEntry csarEntry = item.getValue();
final CsarContentProperties fileProperties = item.getKey();
stringBuilder.append(NAME).append(": ").append(fileProperties.getPathInsideCsar()).append("\n");
String mimeType;
if (csarEntry instanceof DocumentBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_XSD;
} else if (csarEntry instanceof XMLDefinitionsBasedCsarEntry || csarEntry instanceof DefinitionsBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
} else {
mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
}
stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
if (exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_HASHES.name()) && Objects.nonNull(fileProperties.getFileHash())) {
stringBuilder.append(HASH).append(": ").append(fileProperties.getFileHash()).append("\n");
}
if (exportConfiguration.containsKey(CsarExportConfiguration.STORE_IMMUTABLY.name()) && Objects.nonNull(fileProperties.getImmutableAddress())) {
stringBuilder.append(IMMUTABLE_ADDRESS).append(": ").append(fileProperties.getImmutableAddress()).append("\n");
}
stringBuilder.append("\n");
}
String manifestString = stringBuilder.toString();
out.write(manifestString.getBytes());
out.closeEntry();
return manifestString;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class ToscaExportUtil method specifyImports.
private TDefinitions specifyImports(IRepository repository, DefinitionsChildId tcId, Collection<DefinitionsChildId> referencedDefinitionsChildIds) {
TDefinitions entryDefinitions = repository.getDefinitions(tcId);
// BEGIN: Definitions modification
// the "imports" collection contains the imports of Definitions, not of other definitions
// the other definitions are stored in entryDefinitions.getImport()
// we modify the internal definitions object directly. It is not written back to the storage. Therefore, we do not need to clone it
// the imports (pointing to not-definitions (xsd, wsdl, ...)) already have a correct relative URL. (quick hack)
URI uri = (URI) this.exportConfiguration.get(CsarExportConfiguration.REPOSITORY_URI.name());
if (uri != null) {
// we are in the plain-XML mode, the URLs of the imports have to be adjusted
for (TImport i : entryDefinitions.getImport()) {
String loc = i.getLocation();
if (!loc.startsWith("../")) {
LOGGER.warn("Location is not relative for id " + tcId.toReadableString());
}
loc = loc.substring(3);
loc = uri + loc;
// now the location is an absolute URL
i.setLocation(loc);
}
}
// files of imports have to be added to the CSAR, too
for (TImport i : entryDefinitions.getImport()) {
String loc = i.getLocation();
if (Util.isRelativeURI(loc)) {
// locally stored, add to CSAR
GenericImportId iid = new GenericImportId(i);
String fileName = IdUtil.getLastURIPart(loc);
fileName = EncodingUtil.URLdecode(fileName);
RepositoryFileReference ref = new RepositoryFileReference(iid, fileName);
putRefAsReferencedItemInCsar(repository, ref);
}
}
Set<DefinitionsChildId> collect = referencedDefinitionsChildIds.stream().filter(id -> id instanceof NodeTypeImplementationId).collect(Collectors.toSet());
if (collect.stream().anyMatch(DefinitionsChildId::isSelfContained)) {
if (this.exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_DEPENDENCIES.name())) {
referencedDefinitionsChildIds.removeAll(collect.stream().filter(id -> !id.isSelfContained()).collect(Collectors.toList()));
} else if (collect.size() > 1 && collect.stream().anyMatch(id -> !id.isSelfContained())) {
referencedDefinitionsChildIds.removeAll(collect.stream().filter(DefinitionsChildId::isSelfContained).collect(Collectors.toList()));
}
}
// adjust imports: add imports of definitions to it
Collection<TImport> imports = new ArrayList<>();
for (DefinitionsChildId id : referencedDefinitionsChildIds) {
this.addToImports(repository, id, imports);
}
entryDefinitions.getImport().addAll(imports);
// END: Definitions modification
return entryDefinitions;
}
Aggregations