Developing a Payload
This topic explains how the Regulatory Submission Processor Interface provides the ability to generate payloads. Out-of-the-box, the com.ptc.qualitymanagement.regmstr.impl package contains customizable regulatory submission processor classes that are overriden during customization. These classes have an overrideable method called generatePayload which uses a regulatory submission object as a parameter.
Solution
Create a custom regulatory submission processor class that overrides the generatePayload method.
Implement custom payload generation. See the example for a new custom class with the overriden generatePayload method.
Create a services.xconf entry to register your custom class.
Solution Elements
The next table describes the solution element.
Element
Type
Description
generatePayload(RegulatorySubmission regulatorySubmission)
API
Generates the file that will eventually be transmitted to the regulatory agency, and saves it as regulatory content in the REGULATORY_SUBMISSION_PAYLOAD content category.
Default Behavior
The default implementation is primarily intended for the demonstrational and instructional purposes only. The default implementation uses the specified regulatory submission, creates a JSON object with key-value attributes on the object, and saves the file as regulatory content in the REGULATORY_SUBMISSION_PAYLOAD content category. A unique Submission ID is assigned to be included in the regulatory submission payload and will be updated on the regulatory submission object.
Creating Custom Classes
To customize payload generation, create a Java class processor (your processor) that extends SimpleRegulatorySubmissionProcessor, or the appropriate revisable subtype processor, then override the generatePayload method. The revisable subtype processor can be AERSubmissionProcessor, ERSubmissionProcessor, RPSSubmissionProcessor, or UDISubmissionProcessor. In the generatePayload method, use the TransactionRunner class to ensure that the process is run within a transaction. Create a JSON object with key-value attributes from the regulatory submission. Pass the created JSON object as a UTF_8 string to the ByteArrayInputStream class. Use the ConditionalAutoCheckoutRunner class to ensure that the regulatory submission object is checked-out and checked-in, as needed, during the process of saving the regulatory content. Use the RegulatoryContentHelper class in the ConditionalAutoCheckoutRunner wrapper class to save the regulatory content as the REGULATORY_SUBMISSION_PAYLOAD content category. At the end of the method, before returning the regulatory submission object, use the refresh method in the PersistenceHelper class to refresh the object. Then, use the VersionControlHelper’s getLatestIteration method to fetch the latest version of the regulatory submission. It is necessary to use the PersistenceHelper class and the VersionControlHelper’s getLatestIteration method since the ConditionalAutoCheckoutRunner class performs a check-in action on the regulatory submission and iterates the version of the submission.
The next example shows a new custom class with the overriden generatePayload method:
@Override
public RegulatorySubmission generatePayload(RegulatorySubmission regulatorySubmission) throws Exception {
// Check modify permissions.
if(!AccessControlHelper.manager.hasAccess(regulatorySubmission, AccessPermission.MODIFY)) {
throw new WTException(accessResource.class.getName(), accessResource.NOT_AUTHORIZED_EXCEPTION, null);
}

return new TransactionRunner<RegulatorySubmission>() {
@Override
public RegulatorySubmission performBusinessProcess() throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.append("Type", TypeIdentifierHelper.getType(regulatorySubmission));
jsonObject.append("Number", regulatorySubmission.getNumber());
jsonObject.append("Name", regulatorySubmission.getName());
String sid = UUID.randomUUID().toString();
jsonObject.append("SubmissionID", sid);
JSONArray subjectArray = new JSONArray();
if (regulatorySubmission instanceof RegSubmission2) {
WTList subjects = RegulatorySubmissionHelper.service
.getSubjectsForRegulatorySubmission(regulatorySubmission);
for (Object o : subjects) {
subjectArray.put(IdentityFactory.getDisplayIdentifier(o)
.getLocalizedMessage(SessionHelper.getLocale()));
}
} else {
subjectArray.put(regulatorySubmission.getSubject().getDisplayIdentifier()
.getLocalizedMessage(SessionHelper.getLocale()));
}
jsonObject.append("Subjects", subjectArray);

InputStream is = new ByteArrayInputStream(jsonObject.toString().getBytes(StandardCharsets.UTF_8));
String description = "regulatory_submission_payload.json";
return new ConditionalAutoCheckoutRunner<RegulatorySubmission>(regulatorySubmission) {
public RegulatorySubmission performBusinessProcess(RegulatorySubmission regulatorySubmission) throws Exception {
regulatorySubmission.setSubmissionID(sid);
regulatorySubmission = (RegulatorySubmission) PersistenceHelper.manager.save(regulatorySubmission);
return RegulatoryContentHelper.getService().storeRegulatoryContent(regulatorySubmission,
RegulatoryContentCategory.REGULATORY_SUBMISSION_PAYLOAD, description, is);
};
}.invoke();
}
}.invoke();
}
這是否有幫助?