A flow that supports a Compare step loads the project from both sides, determines the delta between each side, and uses only the difference to synchronize the data during the final update.
Unlike the normal flow that consists of four steps (load, convert to Gateway, convert from Gateway, and Update Destination), a flow that supports the Compare step includes the following additional steps:
- Load data from the other application
- Convert the data to the Gateway format
- Compare
The Compare step is supported by the Gateway framework code; providers do not have to implement it. Providers will need to implement the extra load and convert steps as these must be implemented by the provider of the destination application. The destination provider must ask for the key of the project that is being loaded to the source side of the implementation when supporting the compare functionality.
Source Provider
In the project data flow, the source provider needs to communicate to the destination side which project it is loading when the Primavera Gateway loads the initial project data from the source side. To do that, the source provider must implement the getProjectKeyForCompare method in the FlowProvider interface.
Normally, a provider will determine which project it is to load from the filter or the parameters that users set in the Gateway user interface. The implementation of the method needs to return a Gateway side value of this project key.
The following is a sample code snippet from the Project Data flow in SampleProvider.java:
@Override
public Map<String, String> getProjectKeyForCompare(String flowType, FlowContext context) throws ProviderException {
SampleFlowType type = getFlowType(flowType);
switch (type) {
case SyncProjectImport:
String sampleProjectKey = (String) context.getParameter("ImportProjectId");
if (StringUtils.isEmpty(sampleProjectKey)) {
return null;
} else {
Map<String, String> keyMap = new HashMap<String, String>();
keyMap.put("ObjectId", context.getXRefValueByGuest("Project", sampleProjectKey));
keyMap.put("Id", sampleProjectKey);
return keyMap;
}
default:
throw new UnsupportedOperationException("Compare not supported.");
}
}
Destination Provider
Similarly, in the project data flow, the destination provider needs to ask for the project key so that it can load the same project. To do that, the destination provider must implement the methods in the LoadStepContext interface.
The LoadStepContext interface has two methods for this use case:
- isLoadStepForCompare method can tell you whether this load step is invoked as a companion load step for the Compare mechanism.
- getProjectKeyForCompare method can tell you which project you should load. The project key returned by getProjectKeyForCompare is already a destination side value.
The following is a code snippet from the Project Data flow in ProjectLoadStep of the Sample provider:
if (context.isLoadStepForCompare()) {
Map<String, String> projectKeys = context.getProjectKeyForCompare();
String projectId = null;
if (projectKeys != null) {
String objectId = projectKeys.get("ObjectId");
if (StringUtils.isEmpty(objectId)) {
projectId = projectKeys.get("Id");
} else {
projectId = objectId;
}
}
if ((projectId == null) || projectId.isEmpty()) {
return new PDIDocumentImpl();
} else {
return getOneProject(projectId, context);
}
}