use of org.ovirt.engine.api.model.Payload in project ovirt-engine by oVirt.
the class VmMapper method map.
@Mapping(from = VmPayload.class, to = Payload.class)
public static Payload map(VmPayload entity, Payload template) {
if (entity.getDeviceType() != null || entity.getFiles().isEmpty()) {
Payload model = template != null ? template : new Payload();
if (entity.getDeviceType() != null) {
org.ovirt.engine.api.model.VmDeviceType deviceType = map(entity.getDeviceType(), null);
if (deviceType != null) {
model.setType(deviceType);
}
}
model.setVolumeId(entity.getVolumeId());
if (entity.getFiles().size() > 0) {
model.setFiles(new Files());
for (Map.Entry<String, String> entry : entity.getFiles().entrySet()) {
File file = new File();
file.setName(entry.getKey());
file.setContent(entry.getValue());
model.getFiles().getFiles().add(file);
}
}
return model;
}
return null;
}
use of org.ovirt.engine.api.model.Payload in project ovirt-engine by oVirt.
the class V3PayloadInAdapter method adapt.
@Override
public Payload adapt(V3Payload from) {
Payload to = new Payload();
if (from.isSetFiles()) {
to.setFiles(new Files());
to.getFiles().getFiles().addAll(adaptIn(from.getFiles().getFiles()));
}
to.setType(VmDeviceType.fromValue(from.getType()));
if (from.isSetVolumeId()) {
to.setVolumeId(from.getVolumeId());
}
return to;
}
use of org.ovirt.engine.api.model.Payload in project ovirt-engine by oVirt.
the class BackendVmDeviceHelper method setPayload.
public static void setPayload(BackendResource resouce, Vm vm) {
try {
VmPayload payload = resouce.getEntity(VmPayload.class, QueryType.GetVmPayload, new IdQueryParameters(new Guid(vm.getId())), null, true);
if (payload != null) {
Payload p = resouce.getMappingLocator().getMapper(VmPayload.class, Payload.class).map(payload, null);
Payloads payloads = new Payloads();
payloads.getPayloads().add(p);
vm.setPayloads(payloads);
}
} catch (WebApplicationException ex) {
if (ex.getResponse().getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
// It's legal to not receive a payload for this VM, so the exception is caught and ignored.
// (TODO: 'getEntity()' should be refactored to make it the programmer's decision,
// whether to throw an exception or not in case the entity is not found.) Then
// this try-catch won't be necessary.
} else {
throw ex;
}
}
}
use of org.ovirt.engine.api.model.Payload in project ovirt-engine by oVirt.
the class VmMapperTest method testPayloadMapToVmPaylod.
@Test
public void testPayloadMapToVmPaylod() {
Payload payload = new Payload();
payload.setType(VmDeviceType.CDROM);
payload.setVolumeId("CD-VOL");
VmPayload vmPayload = VmMapper.map(payload, null);
assertEquals(payload.getType().name(), vmPayload.getDeviceType().name());
assertEquals(payload.getVolumeId(), vmPayload.getVolumeId());
}
use of org.ovirt.engine.api.model.Payload in project ovirt-engine by oVirt.
the class VmMapperTest method testVmPayloadMapToPaylod.
@Test
public void testVmPayloadMapToPaylod() {
VmPayload vmPayload = new VmPayload();
vmPayload.setDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType.CDROM);
vmPayload.setVolumeId("CD-VOL");
Payload payload = VmMapper.map(vmPayload, null);
assertEquals(vmPayload.getDeviceType().name(), payload.getType().name());
assertEquals(vmPayload.getVolumeId(), payload.getVolumeId());
}
Aggregations