use of org.eclipse.vorto.repository.core.ModelFileContent in project vorto by eclipse.
the class AbstractResolver method matchesServiceKey.
private boolean matchesServiceKey(ModelInfo resource, String targetPlatformKey) {
IModelRepository repository = repositoryFactory.getRepositoryByModel(resource.getId());
ModelFileContent content = repository.getModelContent(resource.getId(), false);
return ((MappingModel) content.getModel()).getTargetPlatform().equals(targetPlatformKey);
}
use of org.eclipse.vorto.repository.core.ModelFileContent in project vorto by eclipse.
the class DefaultResolver method doResolve.
@Override
protected ModelId doResolve(String tenantId, ModelInfo mappingModelResource, ResolveQuery query) {
ModelFileContent content = getRepositoryFactory().getRepository(tenantId).getModelContent(mappingModelResource.getId(), false);
MappingModel mappingModel = (MappingModel) content.getModel();
Optional<MappingRule> objectRule = mappingModel.getRules().stream().filter(rule -> rule.getTarget() instanceof StereoTypeTarget && ((StereoTypeTarget) rule.getTarget()).getName().equals(query.getStereoType())).findFirst();
if (objectRule.isPresent()) {
Optional<Attribute> objectIdAttribute = ((StereoTypeTarget) objectRule.get().getTarget()).getAttributes().stream().filter(attribute -> attribute.getName().equals(query.getAttributeId())).findFirst();
if (objectIdAttribute.isPresent() && objectIdAttribute.get().getValue().equals(query.getAttributeValue())) {
return ModelId.fromReference(mappingModel.getReferences().get(0).getImportedNamespace(), mappingModel.getReferences().get(0).getVersion());
}
}
return null;
}
use of org.eclipse.vorto.repository.core.ModelFileContent in project vorto by eclipse.
the class ModelImporterTest method testUploadSameModelByAdminDraftState.
@Test
public void testUploadSameModelByAdminDraftState() throws Exception {
when(userRepositoryRoleService.isSysadmin(any(User.class))).thenReturn(true);
IUserContext alex = createUserContext("alex", "playground");
ModelInfo info = importModel("Color.type", alex);
this.workflow.start(info.getId(), alex);
IUserContext admin = createUserContext("admin", "playground");
UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream())), Context.create(admin, Optional.empty()));
this.importer.doImport(uploadResult.getHandleId(), Context.create(admin, Optional.empty()));
ModelFileContent content = repositoryFactory.getRepository(admin).getModelContent(uploadResult.getReports().get(0).getModel().getId(), true);
assertTrue(uploadResult.hasWarnings());
assertTrue(new String(content.getContent(), "utf-8").contains("mandatory b as int"));
assertTrue(uploadResult.isValid());
assertTrue(uploadResult.getReport().get(0).isValid());
assertEquals(ValidationReport.WARNING_MODEL_ALREADY_EXISTS, uploadResult.getReport().get(0).getMessage());
}
Aggregations