use of org.candlepin.dto.api.v1.OwnerDTO in project candlepin by candlepin.
the class ConsumerImporter method populateEntity.
/**
* Populates the specified entity with data from the provided DTO.
* This method does not set the upstreamConsumer field.
*
* @param entity
* The entity instance to populate
*
* @param dto
* The DTO containing the data with which to populate the entity
*
* @throws IllegalArgumentException
* if either entity or dto are null
*/
protected void populateEntity(Owner entity, OwnerDTO dto) {
if (entity == null) {
throw new IllegalArgumentException("the owner model entity is null");
}
if (dto == null) {
throw new IllegalArgumentException("the owner dto is null");
}
if (dto.getId() != null) {
entity.setId(dto.getId());
}
if (dto.getDisplayName() != null) {
entity.setDisplayName(dto.getDisplayName());
}
if (dto.getKey() != null) {
entity.setKey(dto.getKey());
}
if (dto.getLastRefreshed() != null) {
entity.setLastRefreshed(dto.getLastRefreshed());
}
if (dto.getContentAccessMode() != null) {
entity.setContentAccessMode(dto.getContentAccessMode());
}
if (dto.getContentAccessModeList() != null) {
entity.setContentAccessModeList(dto.getContentAccessModeList());
}
if (dto.getCreated() != null) {
entity.setCreated(dto.getCreated());
}
if (dto.getUpdated() != null) {
entity.setUpdated(dto.getUpdated());
}
if (dto.getParentOwner() != null) {
// Impl note:
// We do not allow modifying a parent owner through its children, so all we'll do here
// is set the parent owner and ignore everything else; including further nested owners.
OwnerDTO pdto = dto.getParentOwner();
Owner parent = null;
if (pdto.getId() != null) {
// look up by ID
parent = this.curator.find(pdto.getId());
} else if (pdto.getKey() != null) {
// look up by key
parent = this.curator.lookupByKey(pdto.getKey());
}
if (parent == null) {
throw new NotFoundException(i18n.tr("Unable to find parent owner: {0}", pdto));
}
entity.setParentOwner(parent);
}
if (dto.getContentPrefix() != null) {
entity.setContentPrefix(dto.getContentPrefix());
}
if (dto.getDefaultServiceLevel() != null) {
entity.setDefaultServiceLevel(dto.getDefaultServiceLevel());
}
if (dto.getLogLevel() != null) {
entity.setLogLevel(dto.getLogLevel());
}
if (dto.isAutobindDisabled() != null) {
entity.setAutobindDisabled(dto.isAutobindDisabled());
}
}
use of org.candlepin.dto.api.v1.OwnerDTO in project candlepin by candlepin.
the class OwnerResourceTest method ownerWithParentOwnerCanBeCreated.
@Test
public void ownerWithParentOwnerCanBeCreated() {
OwnerDTO parent = new OwnerDTO();
parent.setKey("parent");
parent.setDisplayName("parent");
OwnerDTO child = new OwnerDTO();
child.setKey("child");
child.setDisplayName("child");
child.setParentOwner(parent);
OwnerDTO pout = this.ownerResource.createOwner(parent);
assertNotNull(pout);
assertNotNull(pout.getId());
assertNotNull(this.ownerCurator.find(pout.getId()));
OwnerDTO cout = this.ownerResource.createOwner(child);
assertNotNull(cout);
assertNotNull(cout.getId());
Owner owner = this.ownerCurator.find(cout.getId());
assertNotNull(owner);
assertNotNull(owner.getParentOwner());
assertEquals(pout.getId(), owner.getParentOwner().getId());
}
use of org.candlepin.dto.api.v1.OwnerDTO in project candlepin by candlepin.
the class OwnerResourceTest method undoImportforOwnerWithNoImports.
@Test(expected = NotFoundException.class)
public void undoImportforOwnerWithNoImports() {
OwnerDTO dto = new OwnerDTO();
dto.setKey("owner-with-no-imports");
dto.setDisplayName("foo");
dto = ownerResource.createOwner(dto);
ownerResource.undoImports(dto.getKey(), new UserPrincipal("JarjarBinks", null, true));
}
use of org.candlepin.dto.api.v1.OwnerDTO in project candlepin by candlepin.
the class OwnerResourceTest method ownerWithInvalidParentIdCannotBeCreated.
@Test(expected = NotFoundException.class)
public void ownerWithInvalidParentIdCannotBeCreated() {
OwnerDTO child = new OwnerDTO();
child.setKey("child");
child.setDisplayName("child");
OwnerDTO parent = new OwnerDTO();
parent.setId("parent");
parent.setDisplayName("parent");
child.setParentOwner(parent);
this.ownerResource.createOwner(child);
throw new RuntimeException("OwnerResource should have thrown NotFoundException");
}
use of org.candlepin.dto.api.v1.OwnerDTO in project candlepin by candlepin.
the class OwnerResourceTest method ownerWithInvalidParentKeyCannotBeCreated.
@Test(expected = NotFoundException.class)
public void ownerWithInvalidParentKeyCannotBeCreated() {
OwnerDTO child = new OwnerDTO();
child.setKey("child");
child.setDisplayName("child");
OwnerDTO parent = new OwnerDTO();
parent.setKey("parent");
parent.setDisplayName("parent");
child.setParentOwner(parent);
this.ownerResource.createOwner(child);
throw new RuntimeException("OwnerResource should have thrown NotFoundException");
}
Aggregations