Eli Mesika has uploaded a new change for review.

Change subject: [WIP] API: Adding Job mapper class
......................................................................

[WIP] API: Adding Job mapper class

Change-Id: Id1b95a094dc586e6ebbdacd44e0a034e91602163
Signed-off-by: Eli Mesika <[email protected]>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=872719
---
A 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/JobMapper.java
A 
backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/JobMapperTest.java
2 files changed, 133 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/16160/1

diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/JobMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/JobMapper.java
new file mode 100644
index 0000000..76ba0bc
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/JobMapper.java
@@ -0,0 +1,105 @@
+package org.ovirt.engine.api.restapi.types;
+
+import java.sql.Date;
+import java.util.Calendar;
+
+import org.ovirt.engine.api.model.Status;
+import org.ovirt.engine.api.model.User;
+import org.ovirt.engine.api.restapi.utils.TypeConversionHelper;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.job.JobExecutionStatus;
+import org.ovirt.engine.core.compat.Guid;
+
+public class JobMapper {
+
+    @Mapping(from = org.ovirt.engine.core.common.job.Job.class, to = 
org.ovirt.engine.api.model.Job.class)
+    public static org.ovirt.engine.api.model.Job 
map(org.ovirt.engine.core.common.job.Job entity, org.ovirt.engine.api.model.Job 
job) {
+
+        org.ovirt.engine.api.model.Job model = job != null ? job : new 
org.ovirt.engine.api.model.Job();
+        model.setId(String.valueOf(entity.getId()));
+        model.setActionType(entity.getActionType().name());
+        model.setDescription(entity.getDescription());
+        model.setStatus(map(entity.getStatus(), null));
+        if (entity.getOwnerId() != null) {
+            User user = new User();
+            user.setId(String.valueOf(entity.getOwnerId()));
+            model.setOwner(user);
+        }
+        
model.setStartTime(TypeConversionHelper.toXMLGregorianCalendar(entity.getStartTime(),
 null));
+        if (entity.getEndTime() != null) {
+            
model.setEndTime(TypeConversionHelper.toXMLGregorianCalendar(entity.getEndTime(),
 null));
+        }
+        if (entity.getLastUpdateTime() != null) {
+            
model.setLastUpdated(TypeConversionHelper.toXMLGregorianCalendar(entity.getLastUpdateTime(),
 null));
+        }
+        model.setExternal(entity.isExternal());
+        model.setAutoCleared(entity.isAutoCleared());
+
+        return model;
+    }
+
+    @Mapping(from = org.ovirt.engine.api.model.Job.class, to = 
org.ovirt.engine.core.common.job.Job.class)
+    public static org.ovirt.engine.core.common.job.Job 
map(org.ovirt.engine.api.model.Job job,
+            org.ovirt.engine.core.common.job.Job entity) {
+        org.ovirt.engine.core.common.job.Job target =
+                entity != null ? entity : new 
org.ovirt.engine.core.common.job.Job();
+        target.setId(new Guid(job.getId()));
+        target.setActionType(VdcActionType.valueOf(job.getActionType()));
+        target.setDescription(job.getDescription());
+        target.setStatus(map(job.getStatus()));
+        target.setOwnerId(new Guid(job.getOwner().getId()));
+        
target.setStartTime(job.getStartTime().toGregorianCalendar().getTime());
+        target.setEndTime(job.isSetStartTime() ? 
job.getStartTime().toGregorianCalendar().getTime()
+                : new Date((Calendar.getInstance().getTimeInMillis())));
+
+        target.setLastUpdateTime(job.isSetLastUpdated() ? 
job.getLastUpdated().toGregorianCalendar().getTime()
+                : new Date((Calendar.getInstance().getTimeInMillis())));
+        target.setExternal(job.isExternal());
+        target.setAutoCleared(job.isAutoCleared());
+
+        return target;
+    }
+
+    @Mapping(from = org.ovirt.engine.api.model.Status.class,
+            to = org.ovirt.engine.core.common.job.JobExecutionStatus.class)
+    public static org.ovirt.engine.core.common.job.JobExecutionStatus 
map(org.ovirt.engine.api.model.Status status) {
+        if 
(JobExecutionStatus.STARTED.name().equals(status.getState().toUpperCase())) {
+            return JobExecutionStatus.STARTED;
+        }
+        if 
(JobExecutionStatus.FINISHED.name().equals(status.getState().toUpperCase())) {
+            return JobExecutionStatus.FINISHED;
+        }
+        if 
(JobExecutionStatus.ABORTED.name().equals(status.getState().toUpperCase())) {
+            return JobExecutionStatus.ABORTED;
+        }
+        if 
(JobExecutionStatus.FAILED.name().equals(status.getState().toUpperCase())) {
+            return JobExecutionStatus.FAILED;
+        }
+        return JobExecutionStatus.UNKNOWN;
+    }
+
+    @Mapping(from = org.ovirt.engine.core.common.job.JobExecutionStatus.class,
+            to = org.ovirt.engine.api.model.Status.class)
+    public static org.ovirt.engine.api.model.Status 
map(org.ovirt.engine.core.common.job.JobExecutionStatus status,
+            org.ovirt.engine.api.model.Status incoming) {
+        Status st = new Status();
+        if (JobExecutionStatus.STARTED == status) {
+            st.setState(JobExecutionStatus.STARTED.name());
+            return st;
+        }
+        if (JobExecutionStatus.FINISHED == status) {
+            st.setState(JobExecutionStatus.FINISHED.name());
+            return st;
+        }
+        if (JobExecutionStatus.ABORTED == status) {
+            st.setState(JobExecutionStatus.ABORTED.name());
+            return st;
+        }
+        if (JobExecutionStatus.FAILED == status) {
+            st.setState(JobExecutionStatus.FAILED.name());
+            return st;
+        }
+        st.setState(JobExecutionStatus.UNKNOWN.name());
+        return st;
+    }
+}
diff --git 
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/JobMapperTest.java
 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/JobMapperTest.java
new file mode 100644
index 0000000..0b06765
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/JobMapperTest.java
@@ -0,0 +1,28 @@
+package org.ovirt.engine.api.restapi.types;
+
+
+import org.ovirt.engine.api.model.Job;
+
+public class JobMapperTest extends AbstractInvertibleMappingTest<Job, 
org.ovirt.engine.core.common.job.Job, org.ovirt.engine.core.common.job.Job> {
+
+    public JobMapperTest() {
+        super(org.ovirt.engine.api.model.Job.class,
+                org.ovirt.engine.core.common.job.Job.class,
+                org.ovirt.engine.core.common.job.Job.class);
+    }
+
+    @Override
+    protected void verify(Job model, Job transform) {
+        assertNotNull(transform);
+        assertEquals(model.getId(), transform.getId());
+        assertEquals(model.getDescription(), transform.getDescription());
+    }
+
+    @Override
+    protected Job postPopulate(Job model) {
+        model.getStatus().setState("started");
+        return super.postPopulate(model);
+    }
+
+}
+


-- 
To view, visit http://gerrit.ovirt.org/16160
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1b95a094dc586e6ebbdacd44e0a034e91602163
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to