package com.perforce.polarion.element.event; import java.util.Map; import org.apache.log4j.Logger; import com.perforce.p4java.core.IJob; import com.perforce.polarion.element.field.FieldMapping; import com.perforce.polarion.element.field.WorkItemAdapter; import com.perforce.polarion.element.field.WorkItemField; import com.polarion.alm.tracker.ITrackerService; import com.polarion.alm.tracker.model.IWorkItem; import com.polarion.alm.ws.client.types.tracker.WorkItem; import com.polarion.platform.ITransactionService; import com.polarion.platform.core.PlatformContext; import com.polarion.platform.security.AuthenticationFailedException; import com.polarion.platform.security.ISecurityService; public class WorkItemEvent { private static final Logger log = Logger.getLogger(WorkItemEvent.class); private final ITrackerService trackerService; private final FieldMapping mappings = FieldMapping.getInstance(); /** * Update a Polarion WorkItem given a Perforce Job * * @param job */ public WorkItemEvent() { trackerService = PlatformContext.getPlatform().lookupService(ITrackerService.class); ISecurityService security = PlatformContext.getPlatform().lookupService(ISecurityService.class); try { security.loginUserFromVault("perforce", "system"); } catch (AuthenticationFailedException e) { log.error("Vault login error", e); } } public void create(IJob job) { IWorkItem workItem = (IWorkItem) new WorkItem(); WorkItemAdapter adapter = new WorkItemAdapter(workItem); for (WorkItemField field : WorkItemField.values()) { String jobField = mappings.get(field).getField(); Map<String, Object> map = job.getRawFields(); String value = (String) map.get(jobField); adapter.set(field, value); } workItem = adapter.getWorkItem(); // String wiURI = trackerService.createWorkItem(wi); } public void update(IJob job) { // Get Perforce Job Field names String projField = mappings.get(WorkItemField.PROJECT).getField(); String idField = mappings.get(WorkItemField.ID).getField(); // Get Field values from Perforce Job Map<String, Object> map = job.getRawFields(); String project = (String) map.get(projField); String id = (String) map.get(idField); log.info("Updating WorkItem: " + project + ":" + id); ITransactionService transaction = PlatformContext.getPlatform().lookupService(ITransactionService.class); transaction.beginTx(); boolean failed = true; try { IWorkItem workItem = trackerService.findWorkItem(project, id); WorkItemAdapter adapter = new WorkItemAdapter(workItem); for (WorkItemField field : WorkItemField.getUpdatable()) { String jobField = mappings.get(field).getField(); String value = (String) map.get(jobField); adapter.set(field, value); } workItem.save(); failed = false; } finally { try { transaction.endTx(failed); } catch (Exception e) { log.error("Error ending WorkItem Update transaction.", e); } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 18791 | Paul Allen | Pass WorkItem ID as new WorkItem ID has not been assigned. | ||
#6 | 17833 | Paul Allen | Status and Linked Revisions now bi-directional. | ||
#5 | 17343 | Paul Allen |
Delete protection (when importing jobs only delete if sucessfull) Remove 'User' and use 'ReportedBy' Job Field. |
||
#4 | 17342 | Paul Allen | Delete old Perforce job after Import and Status lookup in Jobspec (or use 'unknown'). | ||
#3 | 17341 | Paul Allen |
Job Import - Import new Jobs to Polarion. Cron definition specifies Polarion WorkItem type for all jobs and a JobView to filter. Perforce counter 'Polarion.Import.Time' used to store last Import and looks at ReportedDate. |
||
#2 | 17338 | Paul Allen | Job scanner - looks for changes to Perforce Jobs and updates the linked WorkItems. | ||
#1 | 16861 | Paul Allen |
Added job query code for scanner. Use Perforce counter to track last scan. JobSpec MUST include fields 'ModifiedBy' and 'ModifiedDate'. - updated p4java 15.2 |