use of org.eclipse.winery.model.converter.support.exception.MultiException in project winery by eclipse.
the class YamlRepository method artifactTemplateExistsInType.
/**
* Checks if artifact templates exists in type
*
* @param targetPath target path of requested type
* @param qName target QName
* @return boolean if it was found
*/
private boolean artifactTemplateExistsInType(Path targetPath, QName qName) {
try {
TDefinitions xmlDefinitions = convertToDefinitions(targetPath, getNameOfTypeFromArtifactName(qName.getLocalPart()), qName.getNamespaceURI());
List<TArtifactTemplate> artifacts = xmlDefinitions.getArtifactTemplates();
for (TArtifactTemplate artifact : artifacts) {
if (artifact.getId().equalsIgnoreCase(getNameOfArtifactFromArtifactName(qName.getLocalPart()))) {
return true;
}
}
} catch (IOException | MultiException e) {
LOGGER.debug("Internal error", e);
}
return false;
}
use of org.eclipse.winery.model.converter.support.exception.MultiException in project winery by eclipse.
the class YamlRepository method definitionsFromRef.
/**
* Gets yaml service template from ref and converts it to xml definitions
*
* @param ref Repository File Reference
* @return xml definitions
*/
@Override
public TDefinitions definitionsFromRef(RepositoryFileReference ref) throws IOException {
Path targetPath = this.ref2AbsolutePath(ref);
if (ref.getParent() instanceof DefinitionsChildId) {
try {
QName name = ((DefinitionsChildId) ref.getParent()).getQName();
TDefinitions definitions = convertToDefinitions(targetPath, name.getLocalPart(), name.getNamespaceURI());
return getRequestedDefinition((DefinitionsChildId) ref.getParent(), definitions);
} catch (MultiException e) {
LOGGER.warn("Internal error", e);
}
}
return null;
}
use of org.eclipse.winery.model.converter.support.exception.MultiException in project winery by eclipse.
the class YamlReader method readServiceTemplate.
/**
* Reads a file and converts it to a ServiceTemplate
*
* @return ServiceTemplate
* @throws MultiException the ServiceTemplate or the file is invalid.
*/
private YTServiceTemplate readServiceTemplate(InputStream inputStream, String namespace) throws MultiException {
Object object = null;
// pre parse checking
try {
object = readObjectFromInputStream(inputStream);
ObjectValidator objectValidator = new ObjectValidator();
objectValidator.validateObject(object);
} catch (ConstructorException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (ScannerException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (InvalidToscaSyntax invalidToscaSyntax) {
invalidToscaSyntax.printStackTrace();
}
// parse checking
return buildServiceTemplate(object, namespace);
}
use of org.eclipse.winery.model.converter.support.exception.MultiException in project winery by eclipse.
the class ImportVisitor method visit.
@Override
public Result visit(YTServiceTemplate node, Parameter parameter) {
YamlReader reader = new YamlReader();
if (!this.namespace.equals(Namespaces.TOSCA_YAML_NS)) {
Set<String> typeDefinitions = new HashSet<>(Arrays.asList(Defaults.TOSCA_NORMATIVE_TYPES, Defaults.TOSCA_NONNORMATIVE_TYPES));
String tmpNamespace = this.namespace;
this.namespace = Namespaces.TOSCA_YAML_NS;
Path tmpDir = Utils.getTmpDir(Paths.get("types"));
for (String typeDefinition : typeDefinitions) {
try {
Path outFilePath = tmpDir.resolve(typeDefinition);
InputStream inputStream = this.getClass().getResourceAsStream(// Do not use File.separator here (https://stackoverflow.com/a/41677152/8235252)
"/".concat(typeDefinition));
Files.copy(inputStream, outFilePath, StandardCopyOption.REPLACE_EXISTING);
YTServiceTemplate serviceTemplate = reader.parseSkipTest(outFilePath, Namespaces.TOSCA_YAML_NS);
if (Objects.nonNull(serviceTemplate)) {
serviceTemplate.accept(this, new Parameter());
}
} catch (MultiException e) {
setException(e);
} catch (Exception e) {
e.printStackTrace();
}
}
this.namespace = tmpNamespace;
}
super.visit(node, parameter);
return null;
}
use of org.eclipse.winery.model.converter.support.exception.MultiException in project winery by eclipse.
the class ImportVisitor method visit.
@Override
public Result visit(YTImportDefinition node, Parameter parameter) {
YamlReader reader = new YamlReader();
String importNamespace = node.getNamespaceUri() == null ? this.namespace : node.getNamespaceUri();
try {
YTServiceTemplate serviceTemplate = reader.parse(node, path, importNamespace);
if (serviceTemplate != null) {
String tmpNamespace = this.namespace;
this.namespace = importNamespace;
this.visit(serviceTemplate, new Parameter());
this.namespace = tmpNamespace;
}
super.visit(node, parameter);
} catch (MultiException e) {
this.setException(e);
}
return null;
}
Aggregations