Search in sources :

Example 86 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class VisibilitySearchSimpleTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    testInfrastructure = new SearchTestInfrastructure();
    testInfrastructure.importModel(testInfrastructure.DATATYPE_MODEL);
    List<ModelInfo> model = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).search("*");
    // this is arguably over-cautious, as the next statement would fail all tests anyway
    if (model.isEmpty()) {
        fail("Model is empty after importing.");
    }
    // "alex" user updates the only imported model's visibility to public
    ModelId updated = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).updateVisibility(model.get(0).getId(), "Public");
    // importing another model as private
    testInfrastructure.importModel(testInfrastructure.INFORMATION_MODEL, testInfrastructure.createUserContext("alex", "playground"));
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId) BeforeClass(org.junit.BeforeClass)

Example 87 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class BlueToothDeviceInfoProfileResolverTest method testResolveInfoModelByDeviceInfoProfileSerialNo.

@Test
public void testResolveInfoModelByDeviceInfoProfileSerialNo() {
    importModel("bluetooth/ColorLight.fbmodel");
    importModel("bluetooth/ColorLightIM.infomodel");
    importModel("bluetooth/ColorLight_bluetooth.mapping");
    DefaultResolver resolver = new DefaultResolver();
    resolver.setRepositoryFactory(repositoryFactory);
    resolver.setSearchService(searchService);
    assertEquals(new ModelId("ColorLightIM", "com.mycompany", "1.0.0"), resolver.resolve(new BluetoothQuery("4810")));
    assertNotNull(repositoryFactory.getRepository(createUserContext("admin")).getById(resolver.resolve(new BluetoothQuery("4810"))));
}
Also used : DefaultResolver(org.eclipse.vorto.repository.core.impl.resolver.DefaultResolver) BluetoothQuery(org.eclipse.vorto.repository.web.core.dto.BluetoothQuery) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 88 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class VisibilitySearchSimpleTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    testInfrastructure = new SearchTestInfrastructure();
    testInfrastructure.importModel(testInfrastructure.DATATYPE_MODEL);
    List<ModelInfo> model = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).search("*");
    // this is arguably over-cautious, as the next statement would fail all tests anyway
    if (model.isEmpty()) {
        fail("Model is empty after importing.");
    }
    // "alex" user updates the only imported model's visibility to public
    ModelId updated = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).updateVisibility(model.get(0).getId(), "Public");
    // importing another model as private
    testInfrastructure.importModel(testInfrastructure.INFORMATION_MODEL, testInfrastructure.createUserContext("alex", "playground"));
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId) BeforeClass(org.junit.BeforeClass)

Example 89 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryController method getUserPolicy.

@PreAuthorize("isAuthenticated() or hasAuthority('model_viewer')")
@GetMapping("/{modelId:.+}/policy")
public ResponseEntity<PolicyEntry> getUserPolicy(@PathVariable final String modelId) {
    Objects.requireNonNull(modelId, "model ID must not be null");
    Authentication user = SecurityContextHolder.getContext().getAuthentication();
    ModelId modelID = ModelId.fromPrettyFormat(modelId);
    String tenantId = getWorkspaceId(modelId);
    try {
        List<PolicyEntry> policyEntries = getPolicyManager(tenantId).getPolicyEntries(modelID).stream().filter(p -> userHasPolicyEntry(p, user, tenantId)).collect(Collectors.toList());
        return getBestPolicyEntryForUser(policyEntries).map(p -> new ResponseEntity<>(p, HttpStatus.OK)).orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
    } catch (NotAuthorizedException ex) {
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    }
}
Also used : InfomodelTemplate(org.eclipse.vorto.repository.web.core.templates.InfomodelTemplate) RequestParam(org.springframework.web.bind.annotation.RequestParam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) ModelAlreadyExistsException(org.eclipse.vorto.repository.core.ModelAlreadyExistsException) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) RequestContextHolder(org.springframework.web.context.request.RequestContextHolder) Future(java.util.concurrent.Future) Map(java.util.Map) Diagnostic(org.eclipse.vorto.repository.core.Diagnostic) AsyncModelMappingsFetcher(org.eclipse.vorto.repository.web.core.async.AsyncModelMappingsFetcher) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ModelParserFactory(org.eclipse.vorto.repository.core.impl.parser.ModelParserFactory) PostMapping(org.springframework.web.bind.annotation.PostMapping) AsyncModelLinksFetcher(org.eclipse.vorto.repository.web.core.async.AsyncModelLinksFetcher) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) User(org.eclipse.vorto.repository.domain.User) Namespace(org.eclipse.vorto.repository.domain.Namespace) RestController(org.springframework.web.bind.annotation.RestController) Executors(java.util.concurrent.Executors) IOUtils(org.apache.commons.io.IOUtils) Permission(org.eclipse.vorto.repository.core.PolicyEntry.Permission) DefaultUserAccountService(org.eclipse.vorto.repository.account.impl.DefaultUserAccountService) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ModelFullDetailsDTO(org.eclipse.vorto.repository.web.api.v1.dto.ModelFullDetailsDTO) ControllerUtils(org.eclipse.vorto.repository.web.ControllerUtils) ModelLink(org.eclipse.vorto.repository.web.api.v1.dto.ModelLink) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) IWorkflowService(org.eclipse.vorto.repository.workflow.IWorkflowService) Lists(com.google.common.collect.Lists) Attachment(org.eclipse.vorto.repository.core.Attachment) AsyncModelSyntaxFetcher(org.eclipse.vorto.repository.web.core.async.AsyncModelSyntaxFetcher) UserRepositoryRoleService(org.eclipse.vorto.repository.services.UserRepositoryRoleService) ModelProperty(org.eclipse.vorto.model.ModelProperty) ModelNotReleasedException(org.eclipse.vorto.repository.model.ModelNotReleasedException) GenericApplicationException(org.eclipse.vorto.repository.web.GenericApplicationException) IOException(java.io.IOException) IModelPolicyManager(org.eclipse.vorto.repository.core.IModelPolicyManager) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) ExecutionException(java.util.concurrent.ExecutionException) HttpStatus(org.springframework.http.HttpStatus) ApiResponse(io.swagger.annotations.ApiResponse) AttachmentValidator(org.eclipse.vorto.repository.core.impl.validation.AttachmentValidator) AttachResult(org.eclipse.vorto.repository.web.api.v1.dto.AttachResult) ModelTemplate(org.eclipse.vorto.repository.web.core.templates.ModelTemplate) PathVariable(org.springframework.web.bind.annotation.PathVariable) ValidationReport(org.eclipse.vorto.repository.importer.ValidationReport) DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) ApiOperation(io.swagger.annotations.ApiOperation) Logger(org.apache.log4j.Logger) AbstractRepositoryController(org.eclipse.vorto.repository.web.AbstractRepositoryController) ByteArrayInputStream(java.io.ByteArrayInputStream) PutMapping(org.springframework.web.bind.annotation.PutMapping) ModelMinimalInfoDTO(org.eclipse.vorto.repository.web.api.v1.dto.ModelMinimalInfoDTO) ZipEntry(java.util.zip.ZipEntry) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) AsyncWorkflowActionsFetcher(org.eclipse.vorto.repository.web.core.async.AsyncWorkflowActionsFetcher) FileContent(org.eclipse.vorto.repository.core.FileContent) IDiagnostics(org.eclipse.vorto.repository.core.IDiagnostics) Collection(java.util.Collection) ModelValidationHelper(org.eclipse.vorto.repository.core.impl.utils.ModelValidationHelper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OperationForbiddenException(org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) Objects(java.util.Objects) List(java.util.List) Principal(java.security.Principal) Optional(java.util.Optional) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) Authentication(org.springframework.security.core.Authentication) IUserContext(org.eclipse.vorto.repository.core.IUserContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) AsyncModelAttachmentsFetcher(org.eclipse.vorto.repository.web.core.async.AsyncModelAttachmentsFetcher) Status(org.eclipse.vorto.repository.web.Status) GetMapping(org.springframework.web.bind.annotation.GetMapping) ExecutorService(java.util.concurrent.ExecutorService) ModelContent(org.eclipse.vorto.repository.web.core.dto.ModelContent) ModelNamespaceNotOfficialException(org.eclipse.vorto.repository.model.ModelNamespaceNotOfficialException) AsyncModelReferenceFetcher(org.eclipse.vorto.repository.web.core.async.AsyncModelReferenceFetcher) IBulkOperationsService(org.eclipse.vorto.repository.model.IBulkOperationsService) UserNamespaceRoleService(org.eclipse.vorto.repository.services.UserNamespaceRoleService) HttpServletResponse(javax.servlet.http.HttpServletResponse) PolicyEntry(org.eclipse.vorto.repository.core.PolicyEntry) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) ModelType(org.eclipse.vorto.model.ModelType) TimeUnit(java.util.concurrent.TimeUnit) ModelResource(org.eclipse.vorto.repository.core.ModelResource) PrincipalType(org.eclipse.vorto.repository.core.PolicyEntry.PrincipalType) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) UserContext(org.eclipse.vorto.repository.core.impl.UserContext) ResponseEntity(org.springframework.http.ResponseEntity) Authentication(org.springframework.security.core.Authentication) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) PolicyEntry(org.eclipse.vorto.repository.core.PolicyEntry) ModelId(org.eclipse.vorto.model.ModelId) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 90 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryController method getPolicies.

@PreAuthorize("isAuthenticated() or hasAuthority('model_viewer')")
@GetMapping("/{modelId:.+}/policies")
public ResponseEntity<Collection<PolicyEntry>> getPolicies(@PathVariable final String modelId) {
    Objects.requireNonNull(modelId, "model ID must not be null");
    try {
        ModelId modelID = ModelId.fromPrettyFormat(modelId);
        String workspaceId = getWorkspaceId(modelId);
        Authentication user = SecurityContextHolder.getContext().getAuthentication();
        return new ResponseEntity<>(getPolicyManager(workspaceId).getPolicyEntries(modelID).stream().filter(p -> userHasPolicyEntry(p, user, workspaceId)).collect(Collectors.toList()), HttpStatus.OK);
    } catch (FatalModelRepositoryException ex) {
        LOGGER.error(ex);
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    } catch (NotAuthorizedException ex) {
        LOGGER.warn(ex);
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Authentication(org.springframework.security.core.Authentication) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) ModelId(org.eclipse.vorto.model.ModelId) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)124 Test (org.junit.Test)48 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)29 IOException (java.io.IOException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ResponseEntity (org.springframework.http.ResponseEntity)14 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)13 ModelType (org.eclipse.vorto.model.ModelType)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Optional (java.util.Optional)10 List (java.util.List)9 IOUtils (org.apache.commons.io.IOUtils)9 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)9 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)8