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"));
}
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"))));
}
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"));
}
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);
}
}
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);
}
}
Aggregations