package com.perforce.polarion.element.event; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import com.perforce.p4java.core.IJob; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.impl.generic.core.Job; import com.perforce.p4java.server.IOptionsServer; import com.perforce.polarion.element.field.FieldMapping; import com.perforce.polarion.element.field.P4JobField; import com.perforce.polarion.element.field.WorkItemField; import com.perforce.polarion.repository.provider.ConnectionFactory; import com.perforce.polarion.repository.provider.P4ExternalRepository; import com.perforce.polarion.repository.provider.P4RepositoryConfiguration; import com.polarion.platform.core.IPlatform; import com.polarion.platform.core.PlatformContext; import com.polarion.platform.repository.external.IExternalRepositoryProvider.IExternalRepository; import com.polarion.platform.repository.external.IExternalRepositoryProviderRegistry; import com.polarion.subterra.base.data.identification.IContextId; public class JobEvent { private static final Logger log = Logger.getLogger(JobEvent.class); protected List<P4RepositoryConfiguration> configs = new ArrayList<>(); public JobEvent(IContextId context) { // Given the context find all the Perforce connections IPlatform platform = PlatformContext.getPlatform(); IExternalRepositoryProviderRegistry service; service = platform.lookupService(IExternalRepositoryProviderRegistry.class); List<IExternalRepository> repositories = service.getRepositories(context); for (IExternalRepository repository : repositories) { if (repository instanceof P4ExternalRepository) { P4ExternalRepository repo = (P4ExternalRepository) repository; configs.add(repo.getConfig()); log.info(repo.getConfig().toString()); } } } public void create(String id, Map<WorkItemField, String> changes) { // each Perforce connection for (P4RepositoryConfiguration config : configs) { IOptionsServer p4 = ConnectionFactory.getConnection(config); try { // fetch each Job field Map<String, Object> fields = toJobSpec(changes); IJob job = new Job(p4, fields); job.update(); } catch (P4JavaException e) { log.warn("Unable to create Job: " + id, e); return; } finally { try { p4.disconnect(); } catch (P4JavaException e) { log.error("Unable to disconnect!", e); } } } } public void delete(String id) { // each Perforce connection for (P4RepositoryConfiguration config : configs) { IOptionsServer p4 = ConnectionFactory.getConnection(config); try { p4.deleteJob(id); } catch (P4JavaException e) { log.warn("Unable to delete Job: " + id, e); return; } finally { try { p4.disconnect(); } catch (P4JavaException e) { log.error("Unable to disconnect!", e); } } } } public void update(String id, Map<WorkItemField, String> changes) { // each Perforce connection for (P4RepositoryConfiguration config : configs) { IOptionsServer p4 = ConnectionFactory.getConnection(config); try { IJob job = p4.getJob(id); // fetch each Job field Map<String, Object> fields = toJobSpec(changes); // Update fields Map<String, Object> current = job.getRawFields(); current.putAll(fields); job.setRawFields(current); job.update(); } catch (P4JavaException e) { log.warn("Unable to update Job: " + id, e); return; } finally { try { p4.disconnect(); } catch (P4JavaException e) { log.error("Unable to disconnect!", e); } } } } private Map<String, Object> toJobSpec(Map<WorkItemField, String> changes) { // Map for each field Map<String, Object> fields = new HashMap<>(); for (Map.Entry<WorkItemField, String> entry : changes.entrySet()) { WorkItemField field = entry.getKey(); String value = entry.getValue(); FieldMapping mappings = FieldMapping.getInstance(); P4JobField jobField = mappings.get(field); if (jobField != null) { fields.put(jobField.getField(), value); } else { log.info("No mapping for Polarion field: " + field.getName()); } } return fields; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 19600 | Paul Allen |
Removed Polarion link to Perforce Job status. Use free text field for PolarionStatus. |
||
#7 | 18028 | Paul Allen |
Polarion WorkItem link for Swarm. Uses Perforce counter 'Polarion.Server.Url' for the Polarion Server e.g. http://phooey-win.das.perforce.com |
||
#6 | 17342 | Paul Allen | Delete old Perforce job after Import and Status lookup in Jobspec (or use 'unknown'). | ||
#5 | 17338 | Paul Allen | Job scanner - looks for changes to Perforce Jobs and updates the linked WorkItems. | ||
#4 | 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 |
||
#3 | 16834 | Paul Allen | Unfix for removed changelists. | ||
#2 | 16772 | Paul Allen | Basic Job Field replication and framework for Fixes. | ||
#1 | 16771 | Paul Allen |
Added Perforce JOB Create/Update/Delete support. Updated p4java to 15.1 |