Search in sources :

Example 1 with EnvironmentContentDTO

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

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

Aggregations

EnvironmentContentDTO (org.candlepin.dto.api.v1.EnvironmentDTO.EnvironmentContentDTO)2 Content (org.candlepin.model.Content)2 EnvironmentContent (org.candlepin.model.EnvironmentContent)2