Search in sources :

Example 1 with NamespaceKey

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);
}
Also used : NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException)

Example 2 with NamespaceKey

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);
}
Also used : NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) Namespace(org.finra.herd.model.api.xml.Namespace) Test(org.junit.Test)

Example 3 with NamespaceKey

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);
}
Also used : NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) NamespaceKeys(org.finra.herd.model.api.xml.NamespaceKeys) Test(org.junit.Test)

Example 4 with NamespaceKey

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) NamespaceAuthorization(org.finra.herd.model.api.xml.NamespaceAuthorization)

Example 5 with NamespaceKey

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());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) Test(org.junit.Test)

Aggregations

NamespaceKey (org.finra.herd.model.api.xml.NamespaceKey)23 Test (org.junit.Test)20 Namespace (org.finra.herd.model.api.xml.Namespace)10 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)5 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 NamespaceKeys (org.finra.herd.model.api.xml.NamespaceKeys)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)1