use of org.eclipse.winery.repository.exceptions.RepositoryCorruptException in project winery by eclipse.
the class BackendUtils method getName.
public static String getName(DefinitionsChildId instanceId) throws RepositoryCorruptException {
IRepository repository = RepositoryFactory.getRepository();
if (!repository.exists(instanceId)) {
throw new RepositoryCorruptException("Definitions does not exist for instance");
}
TExtensibleElements instanceElement = RepositoryFactory.getRepository().getDefinitions(instanceId).getElement();
return ModelUtilities.getNameWithIdFallBack(instanceElement);
}
use of org.eclipse.winery.repository.exceptions.RepositoryCorruptException 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.repository.exceptions.RepositoryCorruptException in project winery by eclipse.
the class ToscaExportUtil method writeDefinitionsElement.
/**
* Writes the Definitions belonging to the given definitgion children to the output stream
*
* @return a collection of DefinitionsChildIds referenced by the given component
* @throws RepositoryCorruptException if tcId does not exist
*/
private Collection<DefinitionsChildId> writeDefinitionsElement(IRepository repository, DefinitionsChildId tcId, OutputStream out) throws JAXBException, RepositoryCorruptException, IOException {
if (!repository.exists(tcId)) {
String error = "Component instance " + tcId.toReadableString() + " does not exist.";
ToscaExportUtil.LOGGER.error(error);
throw new RepositoryCorruptException(error);
}
this.getPrepareForExport(repository, tcId);
Definitions 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(ToscaExportUtil.ExportProperties.REPOSITORY_URI.toString());
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 = Util.getLastURIPart(loc);
fileName = Util.URLdecode(fileName);
RepositoryFileReference ref = new RepositoryFileReference(iid, fileName);
this.putRefAsReferencedItemInCsar(ref);
}
}
Collection<DefinitionsChildId> referencedDefinitionsChildIds = repository.getReferencedDefinitionsChildIds(tcId);
// 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);
if (entryDefinitions.getElement() instanceof TEntityType) {
TEntityType entityType = (TEntityType) entryDefinitions.getElement();
// we have an entity type with a possible properties definition
WinerysPropertiesDefinition wpd = entityType.getWinerysPropertiesDefinition();
if (wpd != null) {
if (wpd.getIsDerivedFromXSD() == null) {
// Write WPD only to file if it exists and is NOT derived from an XSD (which may happen during import)
String wrapperElementNamespace = wpd.getNamespace();
String wrapperElementLocalName = wpd.getElementName();
// BEGIN: add import and put into CSAR
TImport imp = new TImport();
entryDefinitions.getImport().add(imp);
// fill known import values
imp.setImportType(XMLConstants.W3C_XML_SCHEMA_NS_URI);
imp.setNamespace(wrapperElementNamespace);
// add "winerysPropertiesDefinition" flag to import tag to support
Map<QName, String> otherAttributes = imp.getOtherAttributes();
otherAttributes.put(QNames.QNAME_WINERYS_PROPERTIES_DEFINITION_ATTRIBUTE, "true");
// Determine location
String loc = BackendUtils.getImportLocationForWinerysPropertiesDefinitionXSD((EntityTypeId) tcId, uri, wrapperElementLocalName);
if (uri == null) {
ToscaExportUtil.LOGGER.trace("CSAR Export mode. Putting XSD into CSAR");
// CSAR Export mode
// XSD has to be put into the CSAR
Document document = ModelUtilities.getWinerysPropertiesDefinitionXsdAsDocument(wpd);
// loc in import is URLencoded, loc on filesystem isn't
String locInCSAR = Util.URLdecode(loc);
// furthermore, the path has to start from the root of the CSAR; currently, it starts from Definitions/
locInCSAR = locInCSAR.substring(3);
ToscaExportUtil.LOGGER.trace("Location in CSAR: {}", locInCSAR);
this.referencesToPathInCSARMap.put(new DummyRepositoryFileReferenceForGeneratedXSD(document), locInCSAR);
}
imp.setLocation(loc);
// END: add import and put into CSAR
// BEGIN: generate TOSCA conforming PropertiesDefinition
PropertiesDefinition propertiesDefinition = new PropertiesDefinition();
propertiesDefinition.setType(new QName(wrapperElementNamespace, wrapperElementLocalName));
entityType.setPropertiesDefinition(propertiesDefinition);
// END: generate TOSCA conforming PropertiesDefinition
} else {
// noinspection StatementWithEmptyBody
// otherwise WPD exists, but is derived from XSD
// we DO NOT have to remove the winery properties definition from the output to allow "debugging" of the CSAR
}
}
}
// END: Definitions modification
this.writeDefinitionsElement(entryDefinitions, out);
return referencedDefinitionsChildIds;
}
Aggregations