Search in sources :

Example 1 with ModelFileContent

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);
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent)

Example 2 with ModelFileContent

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;
}
Also used : ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) ResolveQuery(org.eclipse.vorto.repository.web.core.dto.ResolveQuery) Service(org.springframework.stereotype.Service) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Optional(java.util.Optional) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.model.ModelId) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 3 with ModelFileContent

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());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) User(org.eclipse.vorto.repository.domain.User) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

ModelFileContent (org.eclipse.vorto.repository.core.ModelFileContent)3 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)2 Optional (java.util.Optional)1 Attribute (org.eclipse.vorto.core.api.model.mapping.Attribute)1 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)1 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)1 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)1 ModelId (org.eclipse.vorto.model.ModelId)1 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)1 IUserContext (org.eclipse.vorto.repository.core.IUserContext)1 User (org.eclipse.vorto.repository.domain.User)1 ResolveQuery (org.eclipse.vorto.repository.web.core.dto.ResolveQuery)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Service (org.springframework.stereotype.Service)1