Search in sources :

Example 1 with GuestIdDTO

use of org.candlepin.dto.api.v1.GuestIdDTO in project candlepin by candlepin.

the class GuestIdResourceTest method updateGuestMismatchedGuestId.

@Test(expected = BadRequestException.class)
public void updateGuestMismatchedGuestId() {
    GuestIdDTO guest = TestUtil.createGuestIdDTO("some_guest");
    guestIdResource.updateGuest(consumer.getUuid(), "other_id", guest);
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) Test(org.junit.Test)

Example 2 with GuestIdDTO

use of org.candlepin.dto.api.v1.GuestIdDTO in project candlepin by candlepin.

the class GuestIdResourceTest method updateGuest.

@Test
public void updateGuest() {
    GuestIdDTO guest = TestUtil.createGuestIdDTO("some_guest");
    GuestId guestEnt = new GuestId();
    guestEnt.setId("some_id");
    guestIdResource.updateGuest(consumer.getUuid(), guest.getGuestId(), guest);
    when(guestIdCurator.findByGuestIdAndOrg(anyString(), any(String.class))).thenReturn(guestEnt);
    ArgumentCaptor<GuestId> guestCaptor = ArgumentCaptor.forClass(GuestId.class);
    Mockito.verify(guestIdCurator, Mockito.times(1)).merge(guestCaptor.capture());
    GuestId result = guestCaptor.getValue();
    assertEquals(consumer, result.getConsumer());
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) GuestId(org.candlepin.model.GuestId) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 3 with GuestIdDTO

use of org.candlepin.dto.api.v1.GuestIdDTO in project candlepin by candlepin.

the class GuestIdResourceTest method updateGuestNoGuestId.

/*
     * Update should add the id from the url to the GuestId object
     * if it does not already have one.
     */
@Test
public void updateGuestNoGuestId() {
    GuestIdDTO guestIdDTO = new GuestIdDTO();
    guestIdResource.updateGuest(consumer.getUuid(), "some_id", guestIdDTO);
    ArgumentCaptor<GuestId> guestCaptor = ArgumentCaptor.forClass(GuestId.class);
    Mockito.verify(guestIdCurator, Mockito.times(1)).merge(guestCaptor.capture());
    GuestId guest = guestCaptor.getValue();
    assertEquals(consumer, guest.getConsumer());
    assertEquals("some_id", guest.getGuestId());
    Mockito.verify(guestIdCurator, Mockito.times(1)).merge(eq(guest));
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) GuestId(org.candlepin.model.GuestId) Test(org.junit.Test)

Example 4 with GuestIdDTO

use of org.candlepin.dto.api.v1.GuestIdDTO 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);
    }
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ConsumerCapability(org.candlepin.model.ConsumerCapability) GuestId(org.candlepin.model.GuestId) Environment(org.candlepin.model.Environment) HypervisorId(org.candlepin.model.HypervisorId) Release(org.candlepin.model.Release)

Example 5 with GuestIdDTO

use of org.candlepin.dto.api.v1.GuestIdDTO in project candlepin by candlepin.

the class GuestIdResource method populateEntities.

/**
 * Populates the specified entities with data from the provided DTOs.
 *
 * @param entities
 *  The entities instance to populate
 *
 * @param dtos
 *  The DTO containing the data with which to populate the entity
 *
 * @throws IllegalArgumentException
 *  if either entity or dto are null
 */
protected void populateEntities(List<GuestId> entities, List<GuestIdDTO> dtos) {
    if (entities == null) {
        throw new IllegalArgumentException("the guestId model entity is null");
    }
    if (dtos == null) {
        throw new IllegalArgumentException("the guestId dto is null");
    }
    for (GuestIdDTO dto : dtos) {
        if (dto == null) {
            continue;
        }
        GuestId guestId = new GuestId();
        populateEntity(guestId, dto);
        entities.add(guestId);
    }
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) GuestId(org.candlepin.model.GuestId)

Aggregations

GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)14 GuestId (org.candlepin.model.GuestId)12 Consumer (org.candlepin.model.Consumer)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)5 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)5 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Consumes (javax.ws.rs.Consumes)3 Produces (javax.ws.rs.Produces)3 Mockito.anyString (org.mockito.Mockito.anyString)3 List (java.util.List)2 PUT (javax.ws.rs.PUT)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)2 Transactional (com.google.inject.persist.Transactional)1 ApiResponses (io.swagger.annotations.ApiResponses)1