Search in sources :

Example 1 with EnvironmentDTO

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

the class EnvironmentTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public EnvironmentDTO populate(ModelTranslator translator, Environment source, EnvironmentDTO dest) {
    dest = super.populate(translator, source, dest);
    dest.setId(source.getId());
    dest.setName(source.getName());
    dest.setDescription(source.getDescription());
    if (translator != null) {
        dest.setOwner(translator.translate(source.getOwner(), OwnerDTO.class));
        Set<EnvironmentContent> envContents = source.getEnvironmentContent();
        if (envContents != null) {
            Collection<EnvironmentContent> envContent = source.getEnvironmentContent();
            dest.setEnvironmentContent(Collections.<EnvironmentContentDTO>emptyList());
            if (envContent != null) {
                ObjectTranslator<Content, ContentDTO> contentTranslator = translator.findTranslatorByClass(Content.class, ContentDTO.class);
                for (EnvironmentContent ec : envContent) {
                    if (ec != null) {
                        ContentDTO dto = contentTranslator.translate(translator, ec.getContent());
                        if (dto != null) {
                            dest.addContent(dto, ec.getEnabled());
                        }
                    }
                }
            }
        }
    } else {
        dest.setOwner(null);
        dest.setEnvironmentContent(null);
    }
    return dest;
}
Also used : EnvironmentContentDTO(org.candlepin.dto.api.v1.EnvironmentDTO.EnvironmentContentDTO) EnvironmentContent(org.candlepin.model.EnvironmentContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 2 with EnvironmentDTO

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

the class EnvironmentTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(Environment source, EnvironmentDTO dto, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getId(), dto.getId());
        assertEquals(source.getName(), dto.getName());
        assertEquals(source.getDescription(), dto.getDescription());
        if (childrenGenerated) {
            this.ownerTranslatorTest.verifyOutput(source.getOwner(), dto.getOwner(), childrenGenerated);
            assertNotNull(dto.getEnvironmentContent());
            for (EnvironmentContent ec : source.getEnvironmentContent()) {
                for (EnvironmentContentDTO ecdto : dto.getEnvironmentContent()) {
                    Content content = ec.getContent();
                    ContentDTO cdto = ecdto.getContent();
                    assertNotNull(cdto);
                    assertNotNull(cdto.getUuid());
                    if (cdto.getUuid().equals(content.getUuid())) {
                        assertEquals(ec.getEnabled(), ecdto.isEnabled());
                        // Pass the content off to the ContentTranslatorTest to verify it
                        this.contentTranslatorTest.verifyOutput(content, cdto, childrenGenerated);
                    }
                }
            }
        } else {
            assertNull(dto.getEnvironmentContent());
            assertNull(dto.getOwner());
        }
    } else {
        assertNull(dto);
    }
}
Also used : EnvironmentContentDTO(org.candlepin.dto.api.v1.EnvironmentDTO.EnvironmentContentDTO) EnvironmentContentDTO(org.candlepin.dto.api.v1.EnvironmentDTO.EnvironmentContentDTO) EnvironmentContent(org.candlepin.model.EnvironmentContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 3 with EnvironmentDTO

use of org.candlepin.dto.api.v1.EnvironmentDTO 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 4 with EnvironmentDTO

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

the class ConsumerResourceUpdateTest method throwsAnExceptionWhenEnvironmentNotFound.

@Test(expected = NotFoundException.class)
public void throwsAnExceptionWhenEnvironmentNotFound() {
    String uuid = "A Consumer";
    EnvironmentDTO changedEnvironment = new EnvironmentDTO().setId("42").setName("environment");
    ConsumerDTO updated = new ConsumerDTO();
    updated.setUuid(uuid);
    updated.setEnvironment(changedEnvironment);
    Consumer existing = getFakeConsumer();
    existing.setUuid(updated.getUuid());
    when(consumerCurator.verifyAndLookupConsumer(existing.getUuid())).thenReturn(existing);
    when(environmentCurator.find(changedEnvironment.getId())).thenReturn(null);
    resource.updateConsumer(existing.getUuid(), updated, principal);
}
Also used : Consumer(org.candlepin.model.Consumer) EnvironmentDTO(org.candlepin.dto.api.v1.EnvironmentDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Aggregations

EnvironmentContentDTO (org.candlepin.dto.api.v1.EnvironmentDTO.EnvironmentContentDTO)2 Content (org.candlepin.model.Content)2 EnvironmentContent (org.candlepin.model.EnvironmentContent)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)1 EnvironmentDTO (org.candlepin.dto.api.v1.EnvironmentDTO)1 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)1 Consumer (org.candlepin.model.Consumer)1 Environment (org.candlepin.model.Environment)1 Test (org.junit.Test)1