/** * Gets a namespace entity and ensure it exists. * * @param namespace the namespace (case insensitive) * * @return the namespace entity * @throws ObjectNotFoundException if the namespace entity doesn't exist */ public NamespaceEntity getNamespaceEntity(String namespace) throws ObjectNotFoundException { NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); if (namespaceEntity == null) { throw new ObjectNotFoundException(String.format("Namespace \"%s\" doesn't exist.", namespace)); } return namespaceEntity; } }
@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); }
/** * Cleans up Herd database after ExecuteJdbcWithReceiveTask test by deleting the test job definition related entities.\ * * @param jobDefinitionNamespace the namespace for the job definition * @param jobDefinitionName the name of the job definition */ @Transactional(propagation = Propagation.REQUIRES_NEW) public void cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(String jobDefinitionNamespace, String jobDefinitionName) { // Retrieve the test job definition entity. JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobDefinitionNamespace, jobDefinitionName); // Delete the test job definition entity. if (jobDefinitionEntity != null) { jobDefinitionDao.delete(jobDefinitionEntity); } // Retrieve the test namespace entity. NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(jobDefinitionNamespace); // Delete the test namespace entity. if (namespaceEntity != null) { namespaceDao.delete(namespaceEntity); } }
@Test public void testDeleteNamespaceUpperCaseParameters() { // Create and persist a namespace entity using lower case values. namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE.toLowerCase()); // Validate that this namespace exists. NamespaceKey namespaceKey = new NamespaceKey(NAMESPACE.toLowerCase()); assertNotNull(namespaceDao.getNamespaceByKey(namespaceKey)); // Delete this namespace using upper case input parameters. Namespace deletedNamespace = namespaceService.deleteNamespace(new NamespaceKey(NAMESPACE.toUpperCase())); // Validate the returned object. namespaceServiceTestHelper.validateNamespace(NAMESPACE.toLowerCase(), deletedNamespace); // Ensure that this namespace is no longer there. assertNull(namespaceDao.getNamespaceByKey(namespaceKey)); }
@Override public NamespaceKeys getNamespaces() { NamespaceKeys namespaceKeys = new NamespaceKeys(); namespaceKeys.getNamespaceKeys().addAll(namespaceDao.getNamespaces()); return namespaceKeys; }
@Override public Namespace deleteNamespace(NamespaceKey namespaceKey) { // Perform validation and trim. namespaceHelper.validateNamespaceKey(namespaceKey); // Retrieve and ensure that a namespace already exists with the specified key. NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespaceKey.getNamespaceCode()); // Delete the namespace. namespaceDao.delete(namespaceEntity); // Create and return the namespace object from the deleted entity. return createNamespaceFromEntity(namespaceEntity); }
/** * Creates and persists a new namespace entity. * * @param namespaceCd the namespace code * * @return the newly created namespace entity. */ public NamespaceEntity createNamespaceEntity(String namespaceCd) { NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(namespaceCd); return namespaceDao.saveAndRefresh(namespaceEntity); }
@Test public void testDeleteNamespaceLowerCaseParameters() { // Create and persist a namespace entity using upper case values. namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE.toUpperCase()); // Validate that this namespace exists. NamespaceKey namespaceKey = new NamespaceKey(NAMESPACE.toUpperCase()); assertNotNull(namespaceDao.getNamespaceByKey(namespaceKey)); // Delete the namespace using lower case input parameters. Namespace deletedNamespace = namespaceService.deleteNamespace(new NamespaceKey(NAMESPACE.toLowerCase())); // Validate the returned object. namespaceServiceTestHelper.validateNamespace(NAMESPACE.toUpperCase(), deletedNamespace); // Ensure that this namespace is no longer there. assertNull(namespaceDao.getNamespaceByKey(namespaceKey)); }
@Override public NamespaceKeys getNamespaces() { NamespaceKeys namespaceKeys = new NamespaceKeys(); namespaceKeys.getNamespaceKeys().addAll(namespaceDao.getNamespaces()); return namespaceKeys; }
@Override public Namespace deleteNamespace(NamespaceKey namespaceKey) { // Perform validation and trim. namespaceHelper.validateNamespaceKey(namespaceKey); // Retrieve and ensure that a namespace already exists with the specified key. NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespaceKey.getNamespaceCode()); // Delete the namespace. namespaceDao.delete(namespaceEntity); // Create and return the namespace object from the deleted entity. return createNamespaceFromEntity(namespaceEntity); }
namespaceDao.saveAndRefresh(namespaceEntity); UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity1 = new UserNamespaceAuthorizationEntity(); userNamespaceAuthorizationEntity1.setUserId("ab");
/** * Gets a namespace entity and ensure it exists. * * @param namespace the namespace (case insensitive) * * @return the namespace entity * @throws ObjectNotFoundException if the namespace entity doesn't exist */ public NamespaceEntity getNamespaceEntity(String namespace) throws ObjectNotFoundException { NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); if (namespaceEntity == null) { throw new ObjectNotFoundException(String.format("Namespace \"%s\" doesn't exist.", namespace)); } return namespaceEntity; } }
@Test public void testDelete() { // Create a namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); // Validate that this namespace entity exists. assertNotNull(namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE))); // Delete the namespace entity. baseJpaDao.delete(namespaceEntity); // Validate that this namespace entity does not exist. assertNull(namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE))); }
@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); }
/** * 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; }
/** * Gets a list of keys for all EMR cluster definitions defined in the system for the specified namespace. * * @param namespace the namespace (case-insensitive) * * @return the list of EMR cluster definition keys */ public List<EmrClusterDefinitionKey> getEmrClusterDefinitionKeys(String namespace) { // Try to retrieve the relative namespace entity. NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); // If namespace entity exists, retrieve EMR cluster definition keys by namespace entity. if (namespaceEntity != null) { return emrClusterDefinitionDao.getEmrClusterDefinitionKeysByNamespace(namespaceEntity); } else { return Lists.newArrayList(); } } }
@Test public void testDetach() { // Create a namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); // Validate that this namespace entity exists. assertNotNull(namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE))); // Detach the namespace entity. baseJpaDao.detach(namespaceEntity); // Try to delete a detached entity. try { baseJpaDao.delete(namespaceEntity); } catch (IllegalArgumentException e) { assertEquals(String.format("Removing a detached instance %s#%s", NamespaceEntity.class.getCanonicalName(), NAMESPACE), e.getMessage()); } }
/** * 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; }
/** * Gets a list of keys for all EMR cluster definitions defined in the system for the specified namespace. * * @param namespace the namespace (case-insensitive) * * @return the list of EMR cluster definition keys */ public List<EmrClusterDefinitionKey> getEmrClusterDefinitionKeys(String namespace) { // Try to retrieve the relative namespace entity. NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); // If namespace entity exists, retrieve EMR cluster definition keys by namespace entity. if (namespaceEntity != null) { return emrClusterDefinitionDao.getEmrClusterDefinitionKeysByNamespace(namespaceEntity); } else { return Lists.newArrayList(); } } }
@Test public void testDeleteNamespace() throws Exception { // Create and persist a namespace entity. namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); // Validate that this namespace exists. NamespaceKey namespaceKey = new NamespaceKey(NAMESPACE); assertNotNull(namespaceDao.getNamespaceByKey(namespaceKey)); // Delete this namespace. Namespace deletedNamespace = namespaceService.deleteNamespace(new NamespaceKey(NAMESPACE)); // Validate the returned object. namespaceServiceTestHelper.validateNamespace(NAMESPACE, deletedNamespace); // Ensure that this namespace is no longer there. assertNull(namespaceDao.getNamespaceByKey(namespaceKey)); }