Search in sources :

Example 1 with OwnerDTO

use of org.candlepin.dto.manifest.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());
    }
}
Also used : Owner(org.candlepin.model.Owner) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) NotFoundException(org.candlepin.common.exceptions.NotFoundException)

Example 2 with OwnerDTO

use of org.candlepin.dto.manifest.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());
}
Also used : Owner(org.candlepin.model.Owner) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Test(org.junit.Test)

Example 3 with OwnerDTO

use of org.candlepin.dto.manifest.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));
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 4 with OwnerDTO

use of org.candlepin.dto.manifest.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");
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Test(org.junit.Test)

Example 5 with OwnerDTO

use of org.candlepin.dto.manifest.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");
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)16 Owner (org.candlepin.model.Owner)16 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)9 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)6 ConsumerType (org.candlepin.model.ConsumerType)5 UserPrincipal (org.candlepin.auth.UserPrincipal)4 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)3 CertificateSerial (org.candlepin.model.CertificateSerial)3 IdentityCertificate (org.candlepin.model.IdentityCertificate)3 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)3 File (java.io.File)2 Date (java.util.Date)2 Access (org.candlepin.auth.Access)2 SubResource (org.candlepin.auth.SubResource)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)2 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)2 OwnerCurator (org.candlepin.model.OwnerCurator)2