use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.
the class JpaOrganizationDao method getByParent.
@Override
@Transactional
public Page<OrganizationImpl> getByParent(String parent, int maxItems, long skipCount) throws ServerException {
requireNonNull(parent, "Required non-null parent");
checkArgument(skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE);
try {
final EntityManager manager = managerProvider.get();
final List<OrganizationImpl> result = manager.createNamedQuery("Organization.getByParent", OrganizationImpl.class).setParameter("parent", parent).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList();
final Long suborganizationsCount = manager.createNamedQuery("Organization.getByParentCount", Long.class).setParameter("parent", parent).getSingleResult();
return new Page<>(result, skipCount, maxItems, suborganizationsCount);
} catch (RuntimeException e) {
throw new ServerException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.
the class OrganizationManagerTest method shouldCreateSuborganization.
@Test
public void shouldCreateSuborganization() throws Exception {
final OrganizationImpl parentOrganization = new OrganizationImpl("org123", "parentOrg", null);
when(organizationDao.getById(anyString())).thenReturn(parentOrganization);
final Organization toCreate = new OrganizationImpl(null, "orgName", parentOrganization.getId());
manager.create(toCreate);
verify(organizationDao).create(organizationCaptor.capture());
final OrganizationImpl createdOrganization = organizationCaptor.getValue();
assertEquals(createdOrganization.getName(), toCreate.getName());
assertEquals(createdOrganization.getQualifiedName(), parentOrganization.getQualifiedName() + "/" + toCreate.getName());
assertEquals(createdOrganization.getParent(), toCreate.getParent());
verify(eventService).publish(persistEventCaptor.capture());
assertEquals(persistEventCaptor.getValue().getOrganization(), createdOrganization);
verify(memberDao).store(new MemberImpl(USER_ID, createdOrganization.getId(), OrganizationDomain.getActions()));
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.
the class OrganizationManager method updateSuborganizationsQualifiedNames.
private void updateSuborganizationsQualifiedNames(String oldQualifiedName, String newQualifiedName) throws NotFoundException, ConflictException, ServerException {
for (OrganizationImpl suborganization : Pages.iterate((maxItems, skipCount) -> organizationDao.getSuborganizations(oldQualifiedName, maxItems, skipCount))) {
suborganization.setQualifiedName(suborganization.getQualifiedName().replaceFirst(oldQualifiedName, newQualifiedName));
organizationDao.update(suborganization);
}
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.
the class OrganizationManager method update.
/**
* Updates organization with new entity.
*
* @param organizationId id of organization to update
* @param update organization update
* @throws NullPointerException when {@code organizationId} or {@code update} is null
* @throws NotFoundException when organization with given id doesn't exist
* @throws ConflictException when name updated with a value which is reserved or is not unique
* @throws ServerException when any other error occurs organization updating
*/
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public Organization update(String organizationId, Organization update) throws NotFoundException, ConflictException, ServerException {
requireNonNull(organizationId, "Required non-null organization id");
requireNonNull(update, "Required non-null organization");
requireNonNull(update.getName(), "Required non-null organization name");
final OrganizationImpl organization = organizationDao.getById(organizationId);
final String oldQualifiedName = organization.getQualifiedName();
final String oldName = organization.getName();
final String newName = update.getName();
final String newQualifiedName = buildQualifiedName(oldQualifiedName, update.getName());
checkNameReservation(newQualifiedName);
organization.setQualifiedName(newQualifiedName);
organizationDao.update(organization);
if (!newName.equals(oldName)) {
updateSuborganizationsQualifiedNames(oldQualifiedName, organization.getQualifiedName());
final String performerName = EnvironmentContext.getCurrent().getSubject().getUserName();
// should be DTO as it sent via json rpc
eventService.publish(asDto(new OrganizationRenamedEvent(performerName, oldName, newName, organization)));
}
return organization;
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.
the class OrganizationManager method create.
/**
* Creates new organization.
*
* @param newOrganization organization to create
* @return created organization
* @throws NullPointerException when {@code organization} is null
* @throws NotFoundException when parent organization was not found
* @throws ConflictException when organization with such id/name already exists
* @throws ConflictException when specified organization name is reserved
* @throws ServerException when any other error occurs during organization creation
*/
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public Organization create(Organization newOrganization) throws NotFoundException, ConflictException, ServerException {
requireNonNull(newOrganization, "Required non-null organization");
requireNonNull(newOrganization.getName(), "Required non-null organization name");
String qualifiedName;
if (newOrganization.getParent() != null) {
final Organization parent = getById(newOrganization.getParent());
qualifiedName = parent.getQualifiedName() + "/" + newOrganization.getName();
} else {
qualifiedName = newOrganization.getName();
}
checkNameReservation(qualifiedName);
final OrganizationImpl organization = new OrganizationImpl(NameGenerator.generate("organization", 16), qualifiedName, newOrganization.getParent());
organizationDao.create(organization);
addFirstMember(organization);
eventService.publish(new OrganizationPersistedEvent(organization)).propagateException();
return organization;
}
Aggregations