Search in sources :

Example 21 with OwnerDTO

use of org.candlepin.dto.manifest.v1.OwnerDTO in project candlepin by candlepin.

the class ConsumerImporterTest method importConsumerWithMismatchedUuidShouldThrowException.

@Test
public void importConsumerWithMismatchedUuidShouldThrowException() throws ImporterException {
    Owner owner = mock(Owner.class);
    OwnerDTO ownerDTO = mock(OwnerDTO.class);
    ConsumerDTO consumer = mock(ConsumerDTO.class);
    when(owner.getUpstreamUuid()).thenReturn("another-test-uuid");
    when(consumer.getUuid()).thenReturn("test-uuid");
    when(consumer.getOwner()).thenReturn(ownerDTO);
    try {
        importer.store(owner, consumer, new ConflictOverrides(), null);
        fail();
    } catch (ImportConflictException e) {
        assertFalse(e.message().getConflicts().isEmpty());
        assertTrue(e.message().getConflicts().contains(Importer.Conflict.DISTRIBUTOR_CONFLICT));
    }
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) Test(org.junit.Test)

Example 22 with OwnerDTO

use of org.candlepin.dto.manifest.v1.OwnerDTO in project candlepin by candlepin.

the class EntitlementImporter 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) {
        OwnerDTO pdto = dto.getParentOwner();
        Owner parent = new Owner();
        if (pdto.getId() != null) {
            parent.setId(pdto.getId());
        }
        if (pdto.getDisplayName() != null) {
            parent.setDisplayName(pdto.getDisplayName());
        }
        if (pdto.getKey() != null) {
            parent.setKey(pdto.getKey());
        }
        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)

Example 23 with OwnerDTO

use of org.candlepin.dto.manifest.v1.OwnerDTO in project candlepin by candlepin.

the class OwnerResource method createEnv.

/**
 * Creates an Environment for an Owner
 *
 * @return an Environment object
 * @httpcode 404
 * @httpcode 200
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/environments")
@ApiOperation(notes = "Creates an Environment for an Owner", value = "Create environment")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public EnvironmentDTO createEnv(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @ApiParam(name = "environment", required = true) EnvironmentDTO envDTO) {
    Environment env = new Environment();
    OwnerDTO ownerDTO = new OwnerDTO().setKey(ownerKey);
    envDTO.setOwner(ownerDTO);
    populateEntity(env, envDTO);
    env = envCurator.create(env);
    return translator.translate(env, EnvironmentDTO.class);
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Environment(org.candlepin.model.Environment) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 24 with OwnerDTO

use of org.candlepin.dto.manifest.v1.OwnerDTO in project candlepin by candlepin.

the class OwnerResource method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO. This method will not set the
 * ID, key, upstream consumer, content access mode list or content access mode fields.
 *
 * @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.getDisplayName() != null) {
        entity.setDisplayName(dto.getDisplayName());
    }
    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.ownerCurator.find(pdto.getId());
        } else if (pdto.getKey() != null) {
            // look up by key
            parent = this.ownerCurator.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) {
        if (dto.getDefaultServiceLevel().isEmpty()) {
            entity.setDefaultServiceLevel(null);
        } else {
            this.serviceLevelValidator.validate(entity.getId(), dto.getDefaultServiceLevel());
            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.api.v1.OwnerDTO) NotFoundException(org.candlepin.common.exceptions.NotFoundException)

Example 25 with OwnerDTO

use of org.candlepin.dto.manifest.v1.OwnerDTO in project candlepin by candlepin.

the class ActivationKeyResourceTest method testUpdateTooLongRelease.

@Test(expected = BadRequestException.class)
public void testUpdateTooLongRelease() {
    ActivationKey key = new ActivationKey();
    OwnerDTO ownerDto = new OwnerDTO();
    key.setOwner(owner);
    key.setName("dd");
    key.setServiceLevel("level1");
    key.setReleaseVer(new Release("release1"));
    activationKeyCurator.create(key);
    ActivationKeyDTO update = new ActivationKeyDTO();
    update.setOwner(ownerDto);
    update.setName("dd");
    update.setServiceLevel("level1");
    update.setReleaseVersion(TestUtil.getStringOfSize(256));
    activationKeyResource.updateActivationKey(key.getId(), update);
}
Also used : ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Release(org.candlepin.model.Release) 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