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;
}
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);
}
}
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);
}
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);
}
Aggregations