target.setStepType(map(step.getType())); target.setStatus(mapStepStatus(step.getStatus()));
@Mapping(from = org.ovirt.engine.core.common.job.Step.class, to = Step.class) public static Step map(org.ovirt.engine.core.common.job.Step entity, Step step) { Step model = step != null ? step : new Step(); model.setId(entity.getId().toString()); if (entity.getParentStepId() != null) { Step parentStep = new Step(); parentStep.setId(entity.getParentStepId().toString()); model.setParentStep(parentStep); } Job job = new Job(); job.setId(entity.getJobId().toString()); model.setJob(job); model.setType(map(entity.getStepType())); model.setDescription(entity.getDescription()); model.setNumber(entity.getStepNumber()); model.setStatus(mapStepStatus(entity.getStatus())); model.setProgress(entity.getProgress()); model.setStartTime(DateMapper.map(entity.getStartTime(), null)); if (entity.getEndTime() != null) { model.setEndTime(TypeConversionHelper.toXMLGregorianCalendar(entity.getEndTime(), null)); } model.setExternal(entity.isExternal()); if (entity.getExternalSystem() != null && entity.getExternalSystem().getType() != null) { model.setExternalType(map(entity.getExternalSystem().getType())); } mapStepSubjectEntities(entity, model); return model; }
@Override public Response add(Step step) { validateParameters(step, "type", "description"); String id; if (step.isSetParentStep()) { validateParameters(step, "parentStep.id"); id = step.getParentStep().getId(); } else { id = jobId.toString(); } return performCreate(ActionType.AddExternalStep, new AddExternalStepParameters(asGuid(id), step.getDescription(), StepMapper.map(step.getType())), new QueryIdResolver<Guid>(QueryType.GetStepWithSubjectEntitiesByStepId, IdQueryParameters.class)); }
@Test public void testSubjectEntities() { org.ovirt.engine.core.common.job.Step bllStep = createBLLStep(); Guid executionHostId = Guid.newGuid(); bllStep.setSubjectEntities( Arrays.asList(new StepSubjectEntity(bllStep.getId(), VdcObjectType.EXECUTION_HOST, executionHostId), new StepSubjectEntity(bllStep.getId(), VdcObjectType.Disk, Guid.Empty))); Step model = StepMapper.map(bllStep, null); assertNotNull(model.getExecutionHost()); assertEquals(executionHostId.toString(), model.getExecutionHost().getId()); bllStep = StepMapper.map(model, null); assertNull(bllStep.getSubjectEntities(), "subject entities shouldn't be mapped back to the model"); }