Package com.avoka.fc.core.service
Class AttachmentService
- java.lang.Object
-
- com.avoka.fc.core.service.BaseService
-
- com.avoka.fc.core.service.CayenneService
-
- com.avoka.fc.core.service.AttachmentService
-
public class AttachmentService extends CayenneService
Provides user document service for managing uploaded file attachments.- See Also:
Attachment
,FileUpload
-
-
Constructor Summary
Constructors Constructor Description AttachmentService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Attachment
addAttachment(Submission submission, String attachmentName, String fileName, byte[] fileData, String userDesciption)
Add the specified file attachment to the submission.Attachment
addAttachment(Submission submission, String attachmentName, String fileName, byte[] fileData, String fileType, String userDesciption)
Add the specified file attachment to the submission.Attachment
addInFormAttachment(Submission submission, byte[] fileData, String fileName, String contentType, RequiredAttachmentMetadata attachmentMetadata, String attachmentKey, boolean isTFieldAttachment)
Add the specified fileData to the submission with the associated required attachment metadata.Attachment
addInFormAttachment(Submission submission, String baseXPath, String filename, byte[] fileData)
Adds an arbitrary file to as an in form attachment to the submission provided.Attachment
addInFormAttachment(Submission submission, org.apache.commons.fileupload.FileItem fileItem, RequiredAttachmentMetadata attachmentMetadata, String attachmentKey)
Add the specified FileItem to the submission with the associated required attachment metadata.Attachment
addInFormSubmitManuallyAttachment(Submission submission, String attachmentKey, String attachmentName, String mandatoryStatus)
Add the specified manually submitted required attachment.Attachment
addInFormSubmitManuallyAttachment(Submission submission, String attachmentKey, String attachmentName, String mandatoryStatus, boolean isTFieldAttachment)
Add the specified manually submitted required attachment.Attachment
addReceiptAsInFormAttachment(Submission submission, Submission receiptSubmission, String baseXPath)
Adds the receipt from a submission as an in form attachment to another submission.boolean
deleteFileUpload(FileUpload fileUpload)
Delete the file upload object.int
getMaxSizeForString(String maxSizeString)
Return the max size for a given string constants.String
getStringForMaxSize(int maxSize)
Return a string representation with a given max size numberstatic boolean
isValidFileName(String fileName)
Return true if the specified attachment filename is valid.static boolean
isValidMediaType(String fileName, byte[] fileData, String mediaType)
Checks attachment if it is of a given media type.boolean
removeAttachment(Object attachmentId)
Remove this attachment and break link between a required attachment, Submission and File upload.boolean
removeAttachmentByKey(String attachmentKey)
Remove this attachment and break link between a required attachment, Submission and File upload.void
removeAttachmentForDynamicData(Attachment attachment)
Remove the submission attachment, file upload and file upload data, and the associated required attachment if only one defined.void
resetAttachmentStatus(Object requiredAttachmentId)
Reset the submission status to before submitManually was called.Attachment
saveArbitaryAttachmentForSubmission(Submission submission, String type, String fileName, byte[] fileData, String mimeType, String description)
Save an optional file attachment for a submission.void
saveEmbeddedAttachmentForSubmission(EmbeddedAttachment embeddedAttachment, Submission submission)
Save the embedded attachment for the given submission.void
saveFileForRequiredAttachment(String fileName, byte[] fileData, String contentType, String description, RequiredAttachment requiredAttachment, String attachmentKey)
Save the uploaded fileItem for form submission requiredAttachmet.void
saveFileForRequiredAttachment(org.apache.commons.fileupload.FileItem fileItem, String description, RequiredAttachment requiredAttachment)
Save the uploaded fileItem for form submission requiredAttachmet.void
setAttachmentsComplete(Submission submission)
Set attachment status of a given submission to be complete.void
submitManually(Object requiredAttachmentId)
Submit the given attachment manually.-
Methods inherited from class com.avoka.fc.core.service.CayenneService
commitChanges, deleteObject, deleteObjects, findObject, getDataContext, getDataDomain, getObjectForPK, getObjectStore, newObject, performNamedQuery, performNamedQuery, performNamedQuery, performNonSelectingQuery, performNonSelectingQuery, performNonSelectingQuery, performNonSelectingQuery, performQuery, performQuery, refetchEntity, refetchObject, registerNewObject, rollbackChanges, toMap, toMap
-
Methods inherited from class com.avoka.fc.core.service.BaseService
getLogger
-
-
-
-
Method Detail
-
addAttachment
public Attachment addAttachment(Submission submission, String attachmentName, String fileName, byte[] fileData, String fileType, String userDesciption)
Add the specified file attachment to the submission.- Parameters:
submission
- the submission record (required)attachmentName
- the required attachment name (required)fileName
- the file name (required)fileData
- the file data (required)fileType
- the file type (required)userDesciption
- the user description- Returns:
- the new attachment
- Since:
- 5.1.7
-
addAttachment
public Attachment addAttachment(Submission submission, String attachmentName, String fileName, byte[] fileData, String userDesciption)
Add the specified file attachment to the submission.- Parameters:
submission
- the submission record (required)attachmentName
- the required attachment name (required)fileName
- the file name (required)fileData
- the file data (required)userDesciption
- the user description- Returns:
- the new attachment
- Since:
- 5.0.0
-
addInFormAttachment
public Attachment addInFormAttachment(Submission submission, byte[] fileData, String fileName, String contentType, RequiredAttachmentMetadata attachmentMetadata, String attachmentKey, boolean isTFieldAttachment)
Add the specified fileData to the submission with the associated required attachment metadata. IfisTFieldAttachment
this method will NOT set the submission attachment status to "Completed", otherwise if will.- Parameters:
submission
- the submission to add the attachment to (required)fileData
- the file data (required)fileName
- the file name (required)contentType
- the content typeattachmentMetadata
- the attachment metadata (required)attachmentKey
- the attachment key (if not specified, a key will be generated)isTFieldAttachment
- specifies if attachment comes from T-Field (attachmentKey is generated and completeAttachments flag must not be set)- Returns:
- the created submission attachment record
- Since:
- 4.2.0
-
addInFormAttachment
public Attachment addInFormAttachment(Submission submission, org.apache.commons.fileupload.FileItem fileItem, RequiredAttachmentMetadata attachmentMetadata, String attachmentKey)
Add the specified FileItem to the submission with the associated required attachment metadata. This method is intended to be called by the FormDynamicDataService for use with in-form attachments. This method will set the submission attachment status as "Completed", so that the attachments page is not displayed and the submission can be completed at submission time.- Parameters:
submission
- the submission to add the attachment to (required)fileItem
- the file upload (required)attachmentMetadata
- the attachment metadata (required)attachmentKey
- the attachment key (optional; if not specified, a key will be generated)- Returns:
- the created submission attachment record
- Since:
- 4.1.0
-
addInFormAttachment
public Attachment addInFormAttachment(Submission submission, String baseXPath, String filename, byte[] fileData)
Adds an arbitrary file to as an in form attachment to the submission provided. Returns the in form attachment added.- Parameters:
submission
- the submission to add the receipt as and in form attachment (required)baseXPath
- the String xPath for the widget (required)filename
- the String filename of the in form attachment (required)fileData
- the byte[] file contents (required)- Returns:
- the created in form attachment
- Since:
- 4.1.0
-
addInFormSubmitManuallyAttachment
public Attachment addInFormSubmitManuallyAttachment(Submission submission, String attachmentKey, String attachmentName, String mandatoryStatus, boolean isTFieldAttachment)
Add the specified manually submitted required attachment. This method is intended to be called by the SyncRestService from T-Field for use with in-form attachments. This method will NOT set the submission attachment status as "Completed"- Parameters:
submission
- the submission to add the attachment to (required)attachmentKey
- the attachment key (optional)attachmentName
- the attachment name (required)mandatoryStatus
- the attachment mandatory status (optional)isTFieldAttachment
- specifies if attachment comes from T-Field (attachmentKey is generated and completeAttachments flag must not be set)- Returns:
- the created submission attachment record
- Since:
- 4.2.0
-
addInFormSubmitManuallyAttachment
public Attachment addInFormSubmitManuallyAttachment(Submission submission, String attachmentKey, String attachmentName, String mandatoryStatus)
Add the specified manually submitted required attachment. This method is intended to be called by the FormDynamicDataService for use with in-form attachments. This method will set the submission attachment status as "Completed", so that the attachments page is not displayed and the submission can be completed at submission time.- Parameters:
submission
- the submission to add the attachment to (required)attachmentKey
- the attachment key (optional)attachmentName
- the attachment name (required)mandatoryStatus
- the attachment mandatory status (optional)- Returns:
- the created submission attachment record
- Since:
- 4.1.0
-
removeAttachment
public boolean removeAttachment(Object attachmentId)
Remove this attachment and break link between a required attachment, Submission and File upload. Note that this method contains database transactions.- Parameters:
attachmentId
- the attachment id- Returns:
- true if the attachment was deleted or false otherwise
-
removeAttachmentByKey
public boolean removeAttachmentByKey(String attachmentKey)
Remove this attachment and break link between a required attachment, Submission and File upload. Note that this method contains database transactions.- Parameters:
attachmentKey
- the attachment id- Returns:
- true if the attachment was deleted or false otherwise
-
removeAttachmentForDynamicData
public void removeAttachmentForDynamicData(Attachment attachment)
Remove the submission attachment, file upload and file upload data, and the associated required attachment if only one defined. This method will not change the submission attachment status, if there are required attachments after this removal operation. However if there are no required attachments after this removal, then the submission attachment status will be set to null. For web inform attachments the submission cannot be Submitted or Completed. However for T.Field syncing this will be will be allowed. This method will purge remove attachment elements from the XML with web submissions, but not T.Field submissions.- Parameters:
attachment
- the submission attachment (required)- Since:
- 4.1.0
-
deleteFileUpload
public boolean deleteFileUpload(FileUpload fileUpload)
Delete the file upload object. Note that this method contains database transactions.- Parameters:
fileUpload
- the upload file (required)- Returns:
- true if the file is deleted.
-
submitManually
public void submitManually(Object requiredAttachmentId)
Submit the given attachment manually. Note that this method contains database transactions.- Parameters:
requiredAttachmentId
- the attachment id
-
resetAttachmentStatus
public void resetAttachmentStatus(Object requiredAttachmentId)
Reset the submission status to before submitManually was called. This is to cater for when user clicked on manual delivery and then changed their mind. Note that this method contains database transactions.- Parameters:
requiredAttachmentId
- the attachment id
-
saveArbitaryAttachmentForSubmission
public Attachment saveArbitaryAttachmentForSubmission(Submission submission, String type, String fileName, byte[] fileData, String mimeType, String description)
Save an optional file attachment for a submission. This method can be used adding arbitrary attachments to a submission.- Parameters:
submission
- the form submission (required)type
- the type of attachment (required)fileName
- the file name (required)fileData
- the file data (required)mimeType
- the file MIME type (optional)description
- the file description (optional)- Returns:
- attachment the newly created attachment
- Since:
- 3.6.0
-
saveEmbeddedAttachmentForSubmission
public void saveEmbeddedAttachmentForSubmission(EmbeddedAttachment embeddedAttachment, Submission submission)
Save the embedded attachment for the given submission.- Parameters:
embeddedAttachment
- the embedded attachmentsubmission
- the form submission
-
saveFileForRequiredAttachment
public void saveFileForRequiredAttachment(org.apache.commons.fileupload.FileItem fileItem, String description, RequiredAttachment requiredAttachment) throws ApplicationException, IOException
Save the uploaded fileItem for form submission requiredAttachmet. Note that this method contains database transactions.- Parameters:
fileItem
- the uploaded file itemdescription
- the description of the filerequiredAttachment
- the associated required attachment- Throws:
ApplicationException
- if the document directory could not be determinedIOException
- if an I/O error occurs
-
saveFileForRequiredAttachment
public void saveFileForRequiredAttachment(String fileName, byte[] fileData, String contentType, String description, RequiredAttachment requiredAttachment, String attachmentKey) throws ApplicationException
Save the uploaded fileItem for form submission requiredAttachmet. Note that this method contains database transactions.- Parameters:
fileName
- the file name (required)fileData
- the file data (required)contentType
- the content type (required)description
- the description of the filerequiredAttachment
- the associated required attachment (required)attachmentKey
- the attachment key- Throws:
ApplicationException
- if the document directory could not be determined
-
setAttachmentsComplete
public void setAttachmentsComplete(Submission submission)
Set attachment status of a given submission to be complete. Note that this method contains database transactions.- Parameters:
submission
- a submission
-
getMaxSizeForString
public int getMaxSizeForString(String maxSizeString)
Return the max size for a given string constants.- Parameters:
maxSizeString
- a string- Returns:
- the max size for a given string
- See Also:
DocumentType.MAX_SIZES
-
getStringForMaxSize
public String getStringForMaxSize(int maxSize)
Return a string representation with a given max size number- Parameters:
maxSize
- a max size number- Returns:
- a string representation with a given max size number
- See Also:
DocumentType.MAX_SIZES
-
addReceiptAsInFormAttachment
public Attachment addReceiptAsInFormAttachment(Submission submission, Submission receiptSubmission, String baseXPath)
Adds the receipt from a submission as an in form attachment to another submission. Returns the InForm attachment added.- Parameters:
submission
- the submission to add the receipt as and in form attachment (required)receiptSubmission
- the submission that contains the receipt PDF (required)baseXPath
- the String xPath for the widget (required)- Returns:
- the in form attachment created (required)
- Since:
- 4.1.0
-
isValidMediaType
public static boolean isValidMediaType(String fileName, byte[] fileData, String mediaType)
Checks attachment if it is of a given media type.- Parameters:
fileName
- file namefileData
- first few bytes of the attachmentmediaType
- the attachment media type- Returns:
- true if attachment if it is of a given media type.
- Since:
- 20.11.0
-
isValidFileName
public static boolean isValidFileName(String fileName)
Return true if the specified attachment filename is valid.- Parameters:
fileName
- the attachment file name to test- Returns:
- true if the attachment file name is valid
- Since:
- 5.0.1
-
-