use of org.candlepin.dto.api.v1.OwnerDTO in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithNullUuidOnOwnerShouldSetUuid.
@Test
public void importConsumerWithNullUuidOnOwnerShouldSetUuid() throws ImporterException {
OwnerDTO ownerDTO = mock(OwnerDTO.class);
Owner owner = mock(Owner.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
when(ownerDTO.getId()).thenReturn("test-owner-id");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
when(consumer.getType()).thenReturn(type);
IdentityCertificate idCert = new IdentityCertificate();
idCert.setSerial(new CertificateSerial());
importer.store(owner, consumer, new ConflictOverrides(), idCert);
// now verify that the owner has the upstream consumer set
ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
verify(owner).setUpstreamConsumer(arg.capture());
assertEquals("test-uuid", arg.getValue().getUuid());
verify(curator).merge(owner);
}
use of org.candlepin.dto.api.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));
}
}
use of org.candlepin.dto.api.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());
}
}
use of org.candlepin.dto.api.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);
}
use of org.candlepin.dto.api.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());
}
}
Aggregations