use of org.candlepin.model.Release in project candlepin by candlepin.
the class ConsumerResource method populateEntity.
/**
* Populates the specified entity with data from the provided DTO, during consumer creation (not update).
* This method will not set the ID, entitlementStatus, complianceStatusHash, idCert, entitlements,
* keyPair and canActivate, because clients are not allowed to create or update those properties.
*
* while autoheal is populated, it is overridden in create method.
*
* owner is not populated because create populates it differently.
*
* @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(Consumer entity, ConsumerDTO dto) {
if (entity == null) {
throw new IllegalArgumentException("the consumer model entity is null");
}
if (dto == null) {
throw new IllegalArgumentException("the consumer dto is null");
}
if (dto.getCreated() != null) {
entity.setCreated(dto.getCreated());
}
if (dto.getName() != null) {
entity.setName(dto.getName());
}
if (dto.getUuid() != null) {
entity.setUuid(dto.getUuid());
}
if (dto.getFacts() != null) {
entity.setFacts(dto.getFacts());
}
if (dto.getUsername() != null) {
entity.setUsername(dto.getUsername());
}
if (dto.getServiceLevel() != null) {
entity.setServiceLevel(dto.getServiceLevel());
}
if (dto.getReleaseVersion() != null) {
entity.setReleaseVer(new Release(dto.getReleaseVersion()));
}
if (dto.getEnvironment() != null) {
Environment env = environmentCurator.find(dto.getEnvironment().getId());
if (env == null) {
throw new NotFoundException(i18n.tr("Environment \"{0}\" could not be found.", dto.getEnvironment().getId()));
}
entity.setEnvironment(env);
}
if (dto.getLastCheckin() != null) {
entity.setLastCheckin(dto.getLastCheckin());
}
if (dto.getCapabilities() != null) {
Set<ConsumerCapability> capabilities = populateCapabilities(entity, dto);
entity.setCapabilities(capabilities);
}
if (dto.getGuestIds() != null) {
List<GuestId> guestIds = new ArrayList<>();
for (GuestIdDTO guestIdDTO : dto.getGuestIds()) {
if (guestIdDTO != null) {
guestIds.add(new GuestId(guestIdDTO.getGuestId(), entity, guestIdDTO.getAttributes()));
}
}
entity.setGuestIds(guestIds);
}
if (dto.getHypervisorId() != null && entity.getOwnerId() != null) {
HypervisorId hypervisorId = new HypervisorId(entity, ownerCurator.findOwnerById(entity.getOwnerId()), dto.getHypervisorId().getHypervisorId(), dto.getHypervisorId().getReporterId());
entity.setHypervisorId(hypervisorId);
}
if (dto.getHypervisorId() == null && dto.getFact("system_uuid") != null && !"true".equals(dto.getFact("virt.is_guest")) && entity.getOwnerId() != null) {
HypervisorId hypervisorId = new HypervisorId(entity, ownerCurator.findOwnerById(entity.getOwnerId()), dto.getFact("system_uuid"));
entity.setHypervisorId(hypervisorId);
}
if (dto.getContentTags() != null) {
entity.setContentTags(dto.getContentTags());
}
if (dto.getAutoheal() != null) {
entity.setAutoheal(dto.getAutoheal());
}
if (dto.getContentAccessMode() != null) {
entity.setContentAccessMode(dto.getContentAccessMode());
}
if (dto.getRecipientOwnerKey() != null) {
entity.setRecipientOwnerKey(dto.getRecipientOwnerKey());
}
if (dto.getAnnotations() != null) {
entity.setAnnotations(dto.getAnnotations());
}
if (dto.getInstalledProducts() != null) {
Set<ConsumerInstalledProduct> installedProducts = populateInstalledProducts(entity, dto);
entity.setInstalledProducts(installedProducts);
}
}
use of org.candlepin.model.Release in project candlepin by candlepin.
the class ConsumerTranslatorTest method initSourceObject.
@Override
protected Consumer initSourceObject() {
ConsumerType ctype = this.consumerTypeTranslatorTest.initSourceObject();
Environment environment = this.environmentTranslatorTest.initSourceObject();
Owner owner = this.ownerTranslatorTest.initSourceObject();
when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
Consumer consumer = new Consumer();
consumer.setId("consumer_id");
consumer.setUuid("consumer_uuid");
consumer.setName("consumer_name");
consumer.setUsername("consumer_user_name");
consumer.setEntitlementStatus("consumer_ent_status");
consumer.setServiceLevel("consumer_service_level");
consumer.setReleaseVer(new Release("releaseVer"));
consumer.setOwner(owner);
consumer.setEnvironment(environment);
consumer.setEntitlementCount(0L);
consumer.setLastCheckin(new Date());
consumer.setCanActivate(Boolean.TRUE);
consumer.setHypervisorId(hypervisorIdTranslatorTest.initSourceObject());
consumer.setAutoheal(Boolean.TRUE);
consumer.setRecipientOwnerKey("test_recipient_owner_key");
consumer.setAnnotations("test_annotations");
consumer.setContentAccessMode("test_content_access_mode");
consumer.setIdCert((IdentityCertificate) this.certificateTranslatorTest.initSourceObject());
consumer.setType(ctype);
Map<String, String> facts = new HashMap<>();
for (int i = 0; i < 5; ++i) {
facts.put("fact-" + i, "value-" + i);
}
consumer.setFacts(facts);
Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerInstalledProduct installedProduct = cipTranslatorTest.initSourceObject();
installedProduct.setId("installedProduct-" + i);
installedProducts.add(installedProduct);
}
consumer.setInstalledProducts(installedProducts);
Set<ConsumerCapability> capabilities = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerCapability capability = capabilityTranslatorTest.initSourceObject();
capability.setName("capability-" + i);
capabilities.add(capability);
}
consumer.setCapabilities(capabilities);
Set<String> contentTags = new HashSet<>();
for (int i = 0; i < 5; ++i) {
contentTags.add("contentTag-" + i);
}
consumer.setContentTags(contentTags);
List<GuestId> guestIds = new LinkedList<>();
for (int i = 0; i < 5; ++i) {
GuestId guestId = guestIdTranslatorTest.initSourceObject();
guestId.setId("guestId-" + i);
guestIds.add(guestId);
}
consumer.setGuestIds(guestIds);
when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
when(mockEnvironmentCurator.find(eq(environment.getId()))).thenReturn(environment);
when(mockEnvironmentCurator.getConsumerEnvironment(eq(consumer))).thenReturn(environment);
return consumer;
}
use of org.candlepin.model.Release in project candlepin by candlepin.
the class ActivationKeyTranslatorTest method initSourceObject.
@Override
protected ActivationKey initSourceObject() {
ActivationKey source = new ActivationKey();
source.setId("key-id");
source.setName("key-name");
source.setDescription("key-description");
source.setOwner(this.ownerTranslatorTest.initSourceObject());
source.setReleaseVer(new Release("key-release-ver"));
source.setServiceLevel("key-service-level");
source.setAutoAttach(true);
Product prod = new Product();
prod.setId("prod-1-id");
source.setProducts(new HashSet<>());
source.addProduct(prod);
Pool pool = new Pool();
pool.setId("pool-1-id");
source.setPools(new HashSet<>());
source.addPool(pool, 1L);
return source;
}
use of org.candlepin.model.Release in project candlepin by candlepin.
the class ConsumerTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public ConsumerDTO populate(ModelTranslator translator, Consumer source, ConsumerDTO dest) {
dest = super.populate(translator, source, dest);
dest.setId(source.getId()).setUuid(source.getUuid()).setName(source.getName()).setUsername(source.getUsername()).setEntitlementStatus(source.getEntitlementStatus()).setServiceLevel(source.getServiceLevel()).setEntitlementCount(source.getEntitlementCount()).setFacts(source.getFacts()).setLastCheckin(source.getLastCheckin()).setCanActivate(source.isCanActivate()).setContentTags(source.getContentTags()).setAutoheal(source.isAutoheal()).setRecipientOwnerKey(source.getRecipientOwnerKey()).setAnnotations(source.getAnnotations()).setContentAccessMode(source.getContentAccessMode());
Release release = source.getReleaseVer();
if (release != null) {
dest.setReleaseVersion(release.getReleaseVer());
}
// Process nested objects if we have a ModelTranslator to use to the translation...
if (translator != null) {
if (StringUtils.isNotEmpty(source.getOwnerId())) {
Owner owner = ownerCurator.findOwnerById(source.getOwnerId());
dest.setOwner(translator.translate(owner, OwnerDTO.class));
}
Environment environment = this.environmentCurator.getConsumerEnvironment(source);
dest.setEnvironment(translator.translate(environment, EnvironmentDTO.class));
Set<ConsumerInstalledProduct> installedProducts = source.getInstalledProducts();
if (installedProducts != null) {
ObjectTranslator<ConsumerInstalledProduct, ConsumerInstalledProductDTO> cipTranslator = translator.findTranslatorByClass(ConsumerInstalledProduct.class, ConsumerInstalledProductDTO.class);
Set<ConsumerInstalledProductDTO> ips = new HashSet<>();
for (ConsumerInstalledProduct cip : installedProducts) {
if (cip != null) {
ConsumerInstalledProductDTO dto = cipTranslator.translate(translator, cip);
if (dto != null) {
ips.add(dto);
}
}
}
dest.setInstalledProducts(ips);
}
Set<ConsumerCapability> capabilities = source.getCapabilities();
if (capabilities != null) {
Set<CapabilityDTO> capabilitiesDTO = new HashSet<>();
ObjectTranslator<ConsumerCapability, CapabilityDTO> capabilityTranslator = translator.findTranslatorByClass(ConsumerCapability.class, CapabilityDTO.class);
for (ConsumerCapability capability : capabilities) {
if (capability != null) {
CapabilityDTO dto = capabilityTranslator.translate(translator, capability);
if (dto != null) {
capabilitiesDTO.add(dto);
}
}
}
dest.setCapabilities(capabilitiesDTO);
}
// Temporary measure to maintain API compatibility
if (source.getTypeId() != null) {
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(source);
dest.setType(translator.translate(ctype, ConsumerTypeDTO.class));
} else {
dest.setType(null);
}
// This will put in the property so that the virtWho instances won't error
dest.setGuestIds(new ArrayList<>());
dest.setHypervisorId(translator.translate(source.getHypervisorId(), HypervisorIdDTO.class));
dest.setIdCert(translator.translate(source.getIdCert(), CertificateDTO.class));
} else {
dest.setReleaseVersion(null);
dest.setOwner(null);
dest.setEnvironment(null);
dest.setInstalledProducts(null);
dest.setCapabilities(null);
dest.setHypervisorId(null);
dest.setType(null);
dest.setIdCert(null);
}
return dest;
}
use of org.candlepin.model.Release in project candlepin by candlepin.
the class ActivationKeyResource method updateActivationKey.
@ApiOperation(notes = "Updates an Activation Key", value = "Update Activation Key")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@PUT
@Path("{activation_key_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ActivationKeyDTO updateActivationKey(@PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @ApiParam(name = "update", required = true) ActivationKeyDTO update) {
ActivationKey toUpdate = activationKeyCurator.verifyAndLookupKey(activationKeyId);
if (update.getName() != null) {
toUpdate.setName(update.getName());
}
String serviceLevel = update.getServiceLevel();
if (serviceLevel != null) {
serviceLevelValidator.validate(toUpdate.getOwner().getId(), serviceLevel);
toUpdate.setServiceLevel(serviceLevel);
}
if (update.getReleaseVersion() != null) {
toUpdate.setReleaseVer(new Release(update.getReleaseVersion()));
}
if (update.getDescription() != null) {
toUpdate.setDescription(update.getDescription());
}
if (update.isAutoAttach() != null) {
toUpdate.setAutoAttach(update.isAutoAttach());
}
toUpdate = activationKeyCurator.merge(toUpdate);
return this.translator.translate(toUpdate, ActivationKeyDTO.class);
}
Aggregations