Search in sources :

Example 1 with ModelEMFResource

use of org.eclipse.vorto.repository.core.impl.ModelEMFResource in project vorto by eclipse.

the class TypeImportValidation method validate.

@Override
public void validate(ModelInfo modelResource, InvocationContext context) throws ValidationException {
    Collection<String> unImportedReferences = Lists.newArrayList();
    ModelEMFResource emfModel = (ModelEMFResource) modelResource;
    Model model = emfModel.getModel();
    if (model == null)
        return;
    if (model instanceof Entity) {
        unImportedReferences.addAll(getUnimportedProperties(((Entity) model).getProperties(), model.getReferences()));
    } else if (model instanceof FunctionblockModel) {
        unImportedReferences.addAll(validateFunctionBlock((FunctionblockModel) model));
    } else if (model instanceof InformationModel) {
        unImportedReferences.addAll(getUnimportedFunctionblocks(((InformationModel) model).getProperties(), model.getReferences()));
    }
    unImportedReferences.forEach(ref -> System.out.println("Missing : " + ref));
    if (!unImportedReferences.isEmpty()) {
        throw new ValidationException(errorMessage(unImportedReferences), modelResource);
    }
}
Also used : Entity(org.eclipse.vorto.core.api.model.datatype.Entity) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ModelEMFResource(org.eclipse.vorto.repository.core.impl.ModelEMFResource) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel)

Example 2 with ModelEMFResource

use of org.eclipse.vorto.repository.core.impl.ModelEMFResource in project vorto by eclipse.

the class AbstractModelParser method parse.

@Override
public ModelInfo parse(InputStream is) {
    XtextResourceSet resourceSet = getInjector().getInstance(XtextResourceSet.class);
    resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    Resource resource = resourceSet.createResource(URI.createURI("dummy:/" + fileName));
    try {
        resource.load(is, resourceSet.getLoadOptions());
    } catch (IOException e) {
        throw new ValidationException(e.getMessage(), null);
    }
    List<org.eclipse.emf.ecore.resource.Resource.Diagnostic> grammarErrors = getGrammarErrors(resource.getErrors());
    if (!grammarErrors.isEmpty()) {
        ModelInfo invalidModelResource = new ModelInfo(parseModelIdFromFileName(), ModelType.fromFileName(fileName));
        throw new ValidationException(grammarErrors.get(0).getMessage(), invalidModelResource);
    }
    return new ModelEMFResource((Model) resource.getContents().get(0));
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) ModelEMFResource(org.eclipse.vorto.repository.core.impl.ModelEMFResource) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) ModelEMFResource(org.eclipse.vorto.repository.core.impl.ModelEMFResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) IOException(java.io.IOException)

Aggregations

ModelEMFResource (org.eclipse.vorto.repository.core.impl.ModelEMFResource)2 IOException (java.io.IOException)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)1 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)1 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)1 Model (org.eclipse.vorto.core.api.model.model.Model)1 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)1 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)1 XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1