use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RequirementTypeId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>(1);
final TRequirementType element = this.getElement(id);
QName requiredCapabilityType = element.getRequiredCapabilityType();
if (requiredCapabilityType != null) {
CapabilityTypeId capId = new CapabilityTypeId(requiredCapabilityType);
ids.add(capId);
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
/**
* Determines the referenced definition children Ids. Does NOT return the included files.
*
* @return a collection of referenced definition child Ids
*/
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ArtifactTemplateId id) throws RepositoryCorruptException {
Collection<DefinitionsChildId> ids = new ArrayList<>();
final TArtifactTemplate artifactTemplate = this.getElement(id);
// "Export" type
QName type = artifactTemplate.getType();
if (type == null) {
throw new RepositoryCorruptException("Type is null for " + id.toReadableString());
} else {
ids.add(new ArtifactTypeId(type));
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class FilebasedRepository method getAllIdsInNamespace.
public Collection<? extends DefinitionsChildId> getAllIdsInNamespace(Class<? extends DefinitionsChildId> clazz, Namespace namespace) {
Collection<DefinitionsChildId> result = new HashSet<>();
String rootPathFragment = Util.getRootPathFragment(clazz);
Path dir = this.repositoryRoot.resolve(rootPathFragment);
dir = dir.resolve(namespace.getEncoded());
if (Files.exists(dir) && Files.isDirectory(dir)) {
DirectoryStream<Path> directoryStream = null;
try {
directoryStream = Files.newDirectoryStream(dir);
for (Path path : directoryStream) {
Constructor<? extends DefinitionsChildId> constructor = null;
constructor = clazz.getConstructor(String.class, String.class, boolean.class);
DefinitionsChildId definitionsChildId = constructor.newInstance(namespace.getDecoded(), path.getFileName().toString(), false);
result.add(definitionsChildId);
}
directoryStream.close();
} catch (IOException e) {
FilebasedRepository.LOGGER.debug("Cannot close ds", e);
} catch (NoSuchMethodException e) {
FilebasedRepository.LOGGER.debug("Cannot find constructor", e);
} catch (InstantiationException e) {
FilebasedRepository.LOGGER.debug("Cannot instantiate object", e);
} catch (IllegalAccessException e) {
FilebasedRepository.LOGGER.debug("IllegalAccessException", e);
} catch (InvocationTargetException e) {
FilebasedRepository.LOGGER.debug("InvocationTargetException", e);
}
}
return result;
}
use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class CsarExporter method writeCsar.
/**
* Writes a complete CSAR containing all necessary things reachable from the given service template
*
* @param entryId the id of the service template to export
* @param out the output stream to write to
*/
public void writeCsar(IRepository repository, DefinitionsChildId entryId, OutputStream out) throws ArchiveException, IOException, JAXBException, RepositoryCorruptException {
CsarExporter.LOGGER.trace("Starting CSAR export with {}", entryId.toString());
Map<RepositoryFileReference, String> refMap = new HashMap<>();
Collection<String> definitionNames = new ArrayList<>();
try (final ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", out)) {
ToscaExportUtil exporter = new ToscaExportUtil();
Map<String, Object> conf = new HashMap<>();
ExportedState exportedState = new ExportedState();
DefinitionsChildId currentId = entryId;
do {
String defName = CsarExporter.getDefinitionsPathInsideCSAR(repository, currentId);
definitionNames.add(defName);
zos.putArchiveEntry(new ZipArchiveEntry(defName));
Collection<DefinitionsChildId> referencedIds;
referencedIds = exporter.exportTOSCA(repository, currentId, zos, refMap, conf);
zos.closeArchiveEntry();
exportedState.flagAsExported(currentId);
exportedState.flagAsExportRequired(referencedIds);
currentId = exportedState.pop();
} while (currentId != null);
// if we export a ServiceTemplate, data for the self-service portal might exist
if (entryId instanceof ServiceTemplateId) {
ServiceTemplateId serviceTemplateId = (ServiceTemplateId) entryId;
this.addSelfServiceMetaData(repository, serviceTemplateId, refMap);
this.addSelfServiceFiles(repository, serviceTemplateId, refMap, zos);
}
// now, refMap contains all files to be added to the CSAR
// write manifest directly after the definitions to have it more at the beginning of the ZIP rather than having it at the very end
this.addManifest(repository, entryId, definitionNames, refMap, zos);
// used for generated XSD schemas
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tFactory.newTransformer();
} catch (TransformerConfigurationException e1) {
CsarExporter.LOGGER.debug(e1.getMessage(), e1);
throw new IllegalStateException("Could not instantiate transformer", e1);
}
// write all referenced files
for (RepositoryFileReference ref : refMap.keySet()) {
String archivePath = refMap.get(ref);
CsarExporter.LOGGER.trace("Creating {}", archivePath);
if (ref instanceof DummyRepositoryFileReferenceForGeneratedXSD) {
addDummyRepositoryFileReferenceForGeneratedXSD(zos, transformer, (DummyRepositoryFileReferenceForGeneratedXSD) ref, archivePath);
} else {
if (ref.getParent() instanceof DirectoryId) {
// special handling for artifact template directories "source" and "files"
addArtifactTemplateToZipFile(zos, repository, ref, archivePath);
} else {
addFileToZipArchive(zos, repository, ref, archivePath);
zos.closeArchiveEntry();
}
}
}
this.addNamespacePrefixes(zos, repository);
}
}
use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class AbstractComponentsResource method getAll.
/**
* Returns resources for all known component instances
* <p>
* Required by XaaSPackager logic
* <p>
* TODO: remove that method and refactor callers
*/
public Collection<AbstractComponentInstanceResource> getAll() {
Class<? extends DefinitionsChildId> idClass = RestUtils.getComponentIdClassForComponentContainer(this.getClass());
SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds = RepositoryFactory.getRepository().getAllDefinitionsChildIds(idClass);
ArrayList<AbstractComponentInstanceResource> res = new ArrayList<>(allDefinitionsChildIds.size());
for (DefinitionsChildId id : allDefinitionsChildIds) {
AbstractComponentInstanceResource r = AbstractComponentsResource.getComponentInstaceResource(id);
res.add(r);
}
return res;
}
Aggregations