use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class NamespaceServiceImpl method createNamespace.
@Override
public Namespace createNamespace(NamespaceCreateRequest request) {
// Perform the validation.
validateNamespaceCreateRequest(request);
// Get the namespace key.
NamespaceKey namespaceKey = new NamespaceKey(request.getNamespaceCode());
// Ensure a namespace with the specified namespace key doesn't already exist.
NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByKey(namespaceKey);
if (namespaceEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create namespace \"%s\" because it already exists.", namespaceKey.getNamespaceCode()));
}
// Create a namespace entity from the request information.
namespaceEntity = createNamespaceEntity(request);
// Persist the new entity.
namespaceEntity = namespaceDao.saveAndRefresh(namespaceEntity);
// Create and return the namespace object from the persisted entity.
return createNamespaceFromEntity(namespaceEntity);
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class NamespaceRestControllerTest method testDeleteNamespace.
@Test
public void testDeleteNamespace() throws Exception {
Namespace namespace = new Namespace(NAMESPACE);
when(namespaceService.deleteNamespace(new NamespaceKey(NAMESPACE))).thenReturn(namespace);
// Delete this namespace.
Namespace deletedNamespace = namespaceRestController.deleteNamespace(NAMESPACE);
// Verify the external calls.
verify(namespaceService).deleteNamespace(new NamespaceKey(NAMESPACE));
verifyNoMoreInteractions(namespaceService);
// Validate the returned object.
assertEquals(namespace, deletedNamespace);
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class NamespaceRestControllerTest method testGetNamespaces.
@Test
public void testGetNamespaces() throws Exception {
NamespaceKeys namespaceKeys = new NamespaceKeys(Arrays.asList(new NamespaceKey(NAMESPACE), new NamespaceKey(NAMESPACE_2)));
when(namespaceService.getNamespaces()).thenReturn(namespaceKeys);
// Retrieve a list of namespace keys.
NamespaceKeys resultNamespaceKeys = namespaceRestController.getNamespaces();
// Verify the external calls.
verify(namespaceService).getNamespaces();
verifyNoMoreInteractions(namespaceService);
// Validate the returned object.
assertEquals(namespaceKeys, resultNamespaceKeys);
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelper method getAllNamespaceAuthorizations.
/**
* Returns a list of namespace authorizations for all namespaces registered in the system and with all permissions enabled.
*
* @return namespacePermissions the list of namespace authorizations
*/
public Set<NamespaceAuthorization> getAllNamespaceAuthorizations() {
Set<NamespaceAuthorization> namespaceAuthorizations = new LinkedHashSet<>();
List<NamespaceKey> namespaceKeys = namespaceDao.getNamespaces();
for (NamespaceKey namespaceKey : namespaceKeys) {
NamespaceAuthorization namespaceAuthorization = new NamespaceAuthorization();
namespaceAuthorizations.add(namespaceAuthorization);
namespaceAuthorization.setNamespace(namespaceKey.getNamespaceCode());
namespaceAuthorization.setNamespacePermissions(getAllNamespacePermissions());
}
return namespaceAuthorizations;
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class NamespaceDaoTest method testGetNamespaceByKey.
@Test
public void testGetNamespaceByKey() {
// Create a namespace entity.
namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Retrieve the namespace entity.
NamespaceEntity resultNamespaceEntity = namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE));
// Validate the results.
assertEquals(NAMESPACE, resultNamespaceEntity.getCode());
}
Aggregations