Go to primary content
Agile Product Lifecycle Management Web Services Guide
Release 9.3.6
E71166-01
  Go To Table Of Contents
Contents

Previous
Previous
 
Next
Next
 

6 Working with File Folders and Attachments

This chapter describes how to work with the Agile PLM File Folders and Attachments, and provides sample code snippets.

6.1 Agile File Folders

A File Folder is a business object that specifies one or more files or URLs that are stored in the file PLM server vault. In addition, a file folder has its own set of tables, indicating that you can create and load an independent file folder and add one or more files to its Files table. You can also search for a file folder, just as you would search for an Item or Change.

The File Folder Base Class has two Classes and each of these classes have their own respective Subclasses. This section describes File Folder features and components, and provides procedures to add, modify, or remove them.

6.2 Managing File Folders

With Agile Web Services you can perform File Folder related tasks, such as:

  • Checking-in and checking-out files associated with the objects in the rows of an Attachments table

  • Adding files and URLs to an Attachments table

  • Deleting Attachments

This section lists and describes these features, and provides necessary procedures to use the Agile Web Services to perform these tasks.


Note:

Additional File Folder attributes are visible for Item Attachments ReadThrough in Web Client (provided they are enabled in the Java Client). Values assigned to these attributes in Web Client are retrieved by Web Services.

6.2.1 Creating a File Folder

You can create a File Folder with the createObject operation, since it is an Agile Object.

Example: Creating a file folder

CreateObjectRequestType createObjectRequestType = new CreateObjectRequestType();
AgileCreateObjectRequest agileCreateObjectRequest[] = new AgileCreateObjectRequest[1];
agileCreateObjectRequest[0] = new AgileCreateObjectRequest();
agileCreateObjectRequest[0].setClassIdentifier("FileFolder");
AgileRowType row_1 = new AgileRowType();

Element number = createMessageElement("number");
number.setTextContent("folderNumber");
row_1.getAny().add(number);
Element description = createMessageElement("description");
description.setTextContent("File Folder Description");
row_1.getAny().add(description);
agileCreateObjectRequest[0].setData(row_1);
createObjectRequestType.setRequests(agileCreateObjectRequest);

Note:

When you add a file or a URL to the row of the Attachments table of a business object, you automatically create a new file folder object that contains the associated file or URL

Example: Creating a Design Object

CreateObjectRequestType createObjectRequestType = new CreateObjectRequestType();                        
AgileCreateObjectRequest agileCreateObjectRequest[] = new AgileCreateObjectRequest[1];
agileCreateObjectRequest[0] = new AgileCreateObjectRequest();
agileCreateObjectRequest[0].setClassIdentifier("Design");
AgileRowType row_1 = new AgileRowType();

Element number = createMessageElement("number");
number.setTextContent("designNumber");
row_1.getAny().add(number);
Element description = createMessageElement("description");
description.setTextContent("Design Description");
row_1.getAny().add(description);
agileCreateObjectRequest[0].setData(row_1); 
createObjectRequestType.setRequests(agileCreateObjectRequest);

6.2.2 Checking Out a File Folder

Before you can add, delete, or modify the files contained in a file folder, you must check out the file folder. With the appropriate privileges, you can check out a file folder if it is not already checked out by another user. Once you check out a file folder, no one else can check it out or modify it.

The user who checked out a file folder and other users (change analysts or component engineers) can check it in. If the file folder was checked out to a location on the network, or to a shared drive or directory, anyone who has access to that network location or to that shared directory can check in the file folder.

Use the operation checkOutFF to check out a file folder.

Example: Checking out a file folder

CheckOutFFRequestType checkOutFFRequestType = new CheckOutFFRequestType();                        
AgileCheckOutFFRequest agileCheckOutFFRequest[] = new AgileCheckOutFFRequest[1];
agileCheckOutFFRequest[0] = new AgileCheckOutFFRequest();
agileCheckOutFFRequest[0].setFolderNumber( folderNumber );
checkOutFFRequestType.setRequests(agileCheckOutFFRequest);

6.2.3 Setting the Version of File Folder Files

A file folder can have several versions. Specify the file version, while adding a file folder to the Attachment table of another business object. The row on the attachments table is then linked to that version. If you do not specify the file version, Agile Web Services uses the default or latest version.

If the parent object containing the Attachments table is an item, you can incorporate the item to lock the specified versions of its attachments.

Example: Setting the version when adding a row to the attachments table

This is carried out in two stages. First, add a row using the operation addRows to add a file folder and then update the table using the operation updateRows.

Stage 1 - Adding the file folder to the attachment table of a Part

AddRowsRequestType addRowsRequestType = new AddRowsRequestType();                        
AgileAddRowsRequest agileAddRowsRequest[] = new AgileAddRowsRequest[1];
agileAddRowsRequest[0] = new AgileAddRowsRequest();
RequestTableType table = new RequestTableType();
table.setClassIdentifier("Part");
table.setObjectNumber( parentPartNumber );
table.setTableIdentifier( "Attachments" );
folderNumber = "FOLDER00441";           
AgileRowType[] rows = new AgileRowType[1];
rows[0] = new AgileRowType();
ObjectReferentIdType objRefId = new ObjectReferentIdType();
objRefId.setClassIdentifier("FileFolder");
objRefId.setObjectIdentifier( folderNumber );
Element element = createMessageElement("folderNumber");             
JAXBContext jc = JAXBContext.newInstance(ObjectReferentIdType.class);
Marshaller marshaller = jc.createMarshaller();
JAXBElement<ObjectReferentIdType> jaxbEl = new JAXBElement<ObjectReferentIdType>(new QName("",element.getNodeName()),
                           ObjectReferentIdType.class, objRefId);
marshaller.marshal(jaxbEl, element);
element =  (Element) element.getFirstChild();
element.setAttribute("xmlns:xsi","http://xmlns.oracle.com/AgileObjects/Core/Common/V1");
element.setAttribute("xsi:type", "ObjectReferentIdType");
row[0].getAny().add(element);
agileAddRowsRequest[0].setRow(rows);
agileAddRowsRequest[0].setObjectInfo(table);
addRowsRequestType.setData(agileAddRowsRequest);
agileUpdateRowsRequest[0].setObjectInfo(updateTable);
RequestTableType updateTable = new RequestTableType();
updateTable.setClassIdentifier( "Part" );
updateTable.setObjectNumber( parentPartNumber);
updateTable.setTableIdentifier( "Attachments" );
AgileUpdateRow updateRow[] = new AgileUpdateRow[1];
updateRow[0] = new AgileUpdateRow();
updateRow[0].setRowId(RowId);
AgileRowType row = new AgileRowType();
MessageElement messages_2[] = new MessageElement[1];                                     
messages_2[0] = new MessageElement(namespaceUri, "folderVersion");
messages_2[0].addAttribute(Constants.NS_PREFIX_SCHEMA_XSI, COMMONNAMESPACEURI, "type", "AgileListEntryType");
AgileListEntryType list = new AgileListEntryType();


Stage 2 - Updating the version of this newly created file folder on the attachment table

SelectionType[] selection = new SelectionType[1];
selection[0] = new SelectionType();
selection[0].setValue("2");
list.setSelection(selection);
Element element = createMessageElement("folderVersion");
JAXBContext jc = JAXBContext.newInstance(AgileListEntryType.class);
Marshaller marshaller = jc.createMarshaller();
JAXBElement<AgileListEntryType> jaxbEl = new JAXBElement<AgileListEntryType>(new QName("",element.getNodeName()),AgileListEntryType.class, list);
marshaller.marshal(jaxbEl, element);
element =  (Element) element.getFirstChild();
element.setAttribute("xmlns:xsi","http://xmlns.oracle.com/AgileObjects/Core/Common/V1");
element.setAttribute("xsi:type", "AgileListEntryType");
row.getAny().add(element);
updateRow[0].setRow(row);
agileUpdateRowsRequest[0].setRow(updateRow);
updateRowsRequestType.setData(agileUpdateRowsRequest);

6.2.4 Canceling a File Folder Checkout

If you check out a file folder and then decide not to modify it, or discard your changes and revert to the original file folder, you can cancel the checkout with the operation cancelCheckOutFF. When you cancel a checkout, the file folder is available for other users to checkout.


Note:

Only the user who checked out a file folder can cancel the checkout.

Example: Canceling a file folder checkout

CancelCheckOutFFRequestType cancelCheckOutFFRequestType = new CancelCheckOutFFRequestType();
AgileCancelCheckOutFFRequest agileCancelCheckOutFFRequest[] = new AgileCancelCheckOutFFRequest[1];
agileCancelCheckOutFFRequest[0] = new AgileCancelCheckOutFFRequest();
agileCancelCheckOutFFRequest[0].setFolderNumber( folderNumber );
cancelCheckOutFFRequestType.setRequests(agileCancelCheckOutFFRequest);

6.2.5 Checking In a File Folder

After you finish working on the checked out file folder, check it in using the operation checkInFF.

When you check in a file folder, it automatically checks in all the (multiple) files that are contained in it, without you having to specifically list each file.

Example: Checking in a file folder

CheckInFFRequestType checkInFFRequestType = new CheckInFFRequestType();
AgileCheckInFFRequest agileCheckInFFRequest[] = new AgileCheckInFFRequest[1];
agileCheckInFFRequest[0] = new AgileCheckInFFRequest();
agileCheckInFFRequest[0].setFolderNumber( folderNumber );
checkInFFRequestType.setRequests(agileCheckInFFRequest);

6.2.6 Deleting the File Folders

To delete a file folder, use the operation "deleteObject." You must have the Delete privilege for file folders to be able to delete them.


Note:

Deleting a file folder does not automatically remove its associated files from the file server. The Agile PLM administrator is responsible for purging deleted files.

To delete a row from the Attachments table of a business object, use the operation "removeRows."

Removing a row from the Attachments table does not delete the associated file folder. You cannot delete a row from the Attachments table in the following situations:

  • The parent object is an Item whose revision is incorporated.

  • The selected attachment is currently checked out.


Note:

Deleting a file folder does not automatically remove its associated files from the file server. The Agile PLM administrator is responsible for purging the deleted files.

Example: Deleting a file folder

DeleteObjectRequestType deleteObjectRequestType = new DeleteObjectRequestType();
AgileDeleteObjectRequest agileDeleteObjectRequest[] = new AgileDeleteObjectRequest[1];
agileDeleteObjectRequest[0] = new AgileDeleteObjectRequest();
agileDeleteObjectRequest[0].setClassIdentifier("FileFolder");
agileDeleteObjectRequest[0].setObjectNumber(folderNumber);
deleteObjectRequestType.setRequests(agileDeleteObjectRequest);

6.3 Getting a File from a File Folder

If a file folder is checked out by another user, you can still get a copy of the file folder file(s) and save it to your local system. You can use the operation getFileFF, which returns the file stream associated with a row of the Attachments table. The file stream can be for one file or it can be a zipped file stream for multiple files, depending on how many files the associated file folder has.

If you call this operation from the file folder object, you return the zipped file stream for all files listed on the Files table. Whereas, if you call this operation from a row of the Files table of a file folder, you return a file stream for the specific file associated with that row.

GetFileFFRequestType getFileFFRequestType = new GetFileFFRequestType();
AgileGetFileFFRequest agileGetFileFFRequest[] = new AgileGetFileFFRequest[1];
agileGetFileFFRequest[0] = new AgileGetFileFFRequest();
agileGetFileFFRequest[0].setFolderNumber(folderNumber);
AgileFileAttachmentRequestType files[] = new AgileFileAttachmentRequestType[1];
files[0] = new AgileFileAttachmentRequestType();
files[0].setRowId(RowId);
agileGetFileFFRequest[0].setFiles(files);
getFileFFRequestType.setRequests(agileGetFileFFRequest);

Example: Getting all the files from a file folder

To get all the files of an Agile File Folder object, set allFiles variable to true.

GetFileFFRequestType getFileFFRequestType = new GetFileFFRequestType();
AgileGetFileFFRequest agileGetFileFFRequest[] = new AgileGetFileFFRequest[1];
agileGetFileFFRequest[0] = new AgileGetFileFFRequest();
agileGetFileFFRequest[0].setFolderNumber(folderNumber);
agileGetFileFFRequest[0].setAllFiles(true);
getFileFFRequestType.setRequests(agileGetFileFFRequest);

6.3.1 Getting a File from a File Folder using a Download URL

When you download extremely large files, use the operation getFileFF to generate a downloadURL for a file attachment present in an Agile File Folder. The request object contains a boolean to indicate that the download URL must be fetched and also the specifications that identify the attachment to be downloaded.

Example: Getting a file using a URL

GetFileFFRequestType getFileFFRequestType = new GetFileFFRequestType();
AgileGetFileFFRequest agileGetFileFFRequest[] = new AgileGetFileFFRequest[1];
agileGetFileFFRequest[0] = new AgileGetFileFFRequest();
agileGetFileFFRequest[0].setFolderNumber(folderNumber);
agileGetFileFFRequest[0].setDownloadUrl(true);
AgileFileAttachmentRequestType files[] = new AgileFileAttachmentRequestType[1];
files[0] = new AgileFileAttachmentRequestType();
files[0].setRowId(rowId);
agileGetFileFFRequest[0].setFiles(files);
getFileFFRequestType.setRequests(agileGetFileFFRequest);

6.3.2 Getting a File from a Version of File Folder

A file attachment can be downloaded from a particular version of an Agile File Folder Object. The request object contains the specifications that identify the attachment to be downloaded and the version of the folder, an array of bytes is obtained in the response object.

Example: Getting a file from a version of a file folder

GetFileFFRequestType getFileFFRequestType = new GetFileFFRequestType();
AgileGetFileFFRequest agileGetFileFFRequest[] = new AgileGetFileFFRequest[1];
agileGetFileFFRequest[0] = new AgileGetFileFFRequest();
agileGetFileFFRequest[0].setFolderNumber(folderNumber);
agileGetFileFFRequest[0].setFolderVersion(folderVersion);
AgileFileAttachmentRequestType files[] = new AgileFileAttachmentRequestType[1];
files[0] = new AgileFileAttachmentRequestType();
files[0].setRowId(rowId);
agileGetFileFFRequest[0].setFiles(files);
getFileFFRequestType.setRequests(agileGetFileFFRequest);

6.4 Adding Files to a File Folder Object

With the operation addFileFF, you can add files to the 'Files' tab of a File Folder. Before you add the files, check-out the File Folder using the operation "checkOutFF."

checkOutFolder(folderNumber);
agileAddFileFFRequestType[0].setFolderNumber(folderNumber);
AddFileFFType files[] = new AddFileFFType[1];
files[0] = new AddFileFFType();
files[0].setFileName("Filename.txt");
files[0].setDescription("Description for file");
files[0].setFileContent( "File Content...file".getBytes() );
agileAddFileFFRequestType[0].setFiles(files);
addFileFFRequestType.setRequest(agileAddFileFFRequestType);

Example: Adding a file using its DFM reference

For the files that were already added to DFM, you can add a file to the 'Files' tab of a file folder using a reference obtained from the DFM file server.

checkOutFolder(folderNumber);
agileAddFileFFRequestType[0].setFolderNumber(folderNumber);
AddFileReferenceFFType reference[] = new AddFileReferenceFFType[1];
reference[0] = new AddFileReferenceFFType();
reference[0].setFileId(fileId);
reference[0].setFileName("FileThrowReference.txt");
reference[0].setDescription("file added using a reference");
reference[0].setFileSize( new Long(1) );
agileAddFileFFRequestType[0].setFileRefs( reference );
addFileFFRequestType.setRequest(agileAddFileFFRequestType);

Example: Adding URLs to a file folder

agileAddFileFFRequestType[0].setFolderNumber(folderNumber);
AddUrlFFType urls[] = new AddUrlFFType[1];
urls[0] = new AddUrlFFType();
urls[0].setUrl("http://www.testurl_filefolder.com");
urls[0].setDescription("Test url description");
agileAddFileFFRequestType[0].setUrls(urls);
addFileFFRequestType.setRequest(agileAddFileFFRequestType);

6.4.1 Adding Files in a File Folder

The Files table of a file folder lists the files and URLs associated with the object. To edit the table, you must first check out the file folder. You cannot add files or URLs to the Files table or delete them unless the file folder is checked out.

Example: Adding a URL in a file folder

Addition of URL attachments to the 'Files' tab of a file folder object can be carried out by specifying the URL and folder number.

checkOutFolder(folderNumber);
agileAddFileFFRequestType[0].setFolderNumber(folderNumber);
AddUrlFFType urls[] = new AddUrlFFType[1];
urls[0] = new AddUrlFFType();
urls[0].setUrl("http://www.testurl_filefolder.com");
urls[0].setDescription("Test url description");
agileAddFileFFRequestType[0].setUrls(urls);
addFileFFRequestType.setRequest(agileAddFileFFRequestType);

6.5 Managing Attachments

Attachments to objects contain information about the object or a manufacturing process. You can attach files and URLs by referencing them in a File Folder object. The File Folder object holds pertinent content, or Attachments. Most primary Agile API objects, such as Item, Change, Manufacturer, ManufacturerPart, Package, TransferOrder, User, and UserGroup, have an attachments table (or tab in the Java Client) that lists indirect references to the files or URLs that are in separate file folders. Each row in an Attachments table can refer to one file or to all files from a referenced file folder.

6.5.1 Getting Attachments of an Object

A file attachment is retrieved using the operation getFileAttachment. When the required file is present in a single, separate row, it is downloaded from the attachment tab using its rowId.

When there are several files in the same row and the desired file is one of them, the fileId must also be specified.

Example: Getting a single attachment

agileGetFileAttachmentRequest[0].setClassIdentifier("Part");
agileGetFileAttachmentRequest[0].setObjectNumber(partNumber);
agileGetFileAttachmentRequest[0].setAllFiles(false);
AgileFileAttachmentRequestType attachments[] = new AgileFileAttachmentRequestType[1];
attachments[0] = new AgileFileAttachmentRequestType();
attachments[0].setRowId(rowId);
agileGetFileAttachmentRequest[0].setAttachments(attachments);
GetFileAttachmentRequestType.setRequests(agileGetFileAttachmentRequest);

Example: Getting all the attachments of an object

To get all the attachments of an object, set allFiles to True.

agileGetFileAttachmentRequest[0].setClassIdentifier("Part");
agileGetFileAttachmentRequest[0].setObjectNumber(partNumber);
agileGetFileAttachmentRequest[0].setAllFiles(true);
AgileFileAttachmentRequestType attachments[] = new AgileFileAttachmentRequestType[1];
attachments[0] = new AgileFileAttachmentRequestType();
agileGetFileAttachmentRequest[0].setAttachments(attachments);
GetFileAttachmentRequestType.setRequests(agileGetFileAttachmentRequest);

6.5.1.1 Getting a Specific Attachment and a File Folder

When there are several files in the same row and the desired file is one of them, then a file can be downloaded from the attachment tab using its fileId along with the rowId. Using the rowId alone in this case is ineffective since all the files of that row will be obtained. To download only a specific file from such a set of files in a single row, the fileId is also needed.

For such cases, first set the rowId information, then obtain the fileId value and set the same into the 'files' element of the request object.

agileGetFileAttachmentRequest[0].setClassIdentifier("Part");
agileGetFileAttachmentRequest[0].setObjectNumber(partNumber);
agileGetFileAttachmentRequest[0].setAllFiles(false);
AgileFileAttachmentRequestType attachments[] = new AgileFileAttachmentRequestType[1];
attachments[0] = new AgileFileAttachmentRequestType();
attachments[0].setRowId(rowId);
int fileIds[] = new int[] { fileId1, fileId2 ) };
attachments[0].setFiles(fileIds);
agileGetFileAttachmentRequest[0].setAttachments(attachments);
GetFileAttachmentRequestType.setRequests(agileGetFileAttachmentRequest);

Instead of using the fileId for obtaining a file from a row with multiple files, you can also use the rowId of the files tab in the filefolder object vis-a-vis the desired file.

To download only a specific file from a set of files in a single row in the Attachment tab, first set the rowId information, then obtain the rowId value of the corresponding FileFolder object of the file and set the same into the 'files' element of request object.

Removing a table rowagileGetFileAttachmentRequest[0].setClassIdentifier("Part");
agileGetFileAttachmentRequest[0].setObjectNumber(partNumber);
agileGetFileAttachmentRequest[0].setAllFiles(false);
AgileFileAttachmentRequestType attachments[] = new AgileFileAttachmentRequestType[1];
attachments[0] = new AgileFileAttachmentRequestType();
attachments[0].setRowId(rowId);
int fileIds[] = new int[] { fileFolderRowId1, fileFolderRowId2 };
attachments[0].setFiles(fileIds);
agileGetFileAttachmentRequest[0].setAttachments(attachments);
GetFileAttachmentRequestType.setRequests(agileGetFileAttachmentRequest);

6.5.1.2 Getting a Specific Attachment using a URL

GetFileAttachmentRequestType GetFileAttachmentRequestType = new GetFileAttachmentRequestType();
AgileGetFileAttachmentRequest agileGetFileAttachmentRequest[] = new AgileGetFileAttachmentRequest[1];
agileGetFileAttachmentRequest[0] = new AgileGetFileAttachmentRequest();
agileGetFileAttachmentRequest[0].setClassIdentifier("Part");
agileGetFileAttachmentRequest[0].setObjectNumber(partNumber);
agileGetFileAttachmentRequest[0].setAllFiles(false);
agileGetFileAttachmentRequest[0].setDownloadUrl(true);
AgileFileAttachmentRequestType attachments[] = new AgileFileAttachmentRequestType[1];
attachments[0] = new AgileFileAttachmentRequestType();
attachments[0].setRowId(rowId);
agileGetFileAttachmentRequest[0].setAttachments(attachments);
GetFileAttachmentRequestType.setRequests(agileGetFileAttachmentRequest);

6.5.2 Adding Attachments to an Object

When you add a file or a URL to the Attachments table of a business object, the server automatically creates a new file folder containing the associated file or URL. The new row on the Attachments table references the new file folder. Use the operation addFileAttachment to add a File or a URL.

When you add a URL attachment, the server stores a reference to the Internet location but does not upload a file. Therefore, you cannot download a URL attachment. Agile Web Services validate URL strings that you attempt to check in as an attachment. If a URL is invalid, the Agile Web Services consider the string a filename instead of a URL.

You cannot add a file or URL to the Attachments table of an item if:

  • The current revision has a pending or released MCO.

  • The current revision is incorporated.

To add attachments, you must specify the unique object to whose attachment tab the files will be added. Also, specify its class identifier and object number information.

The exact specification of the attachment to be added is defined as an object of type AgileAddFileAttachmentRequestType. This object includes information about the name of the file and its description and content.

Example: Adding an attachment to a Part.

You can specify if multiple attachments must add into a single folder or multiple folders by supplying boolean value to setSingleFolder.

AddFileAttachmentRequestType addFileAttachmentRequestType = new AddFileAttachmentRequestType();
AgileAddFileAttachmentRequest agileAddFileAttachmentRequest = new AgileAddFileAttachmentRequest();
agileAddFileAttachmentRequest = new AgileAddFileAttachmentRequest();
agileAddFileAttachmentRequest.setClassIdentifier("Part");
agileAddFileAttachmentRequest.setObjectNumber( partNumber );
AgileAddFileAttachmentRequestType attachments = new AgileAddFileAttachmentRequestType();
attachments = new AgileAddFileAttachmentRequestType();
attachments.setName("Filename.txt");
attachments.setDescription("Description for file ");
File file = File.createTempFile("Filename", "txt");
FileWriter writer  = new FileWriter(file);
writer.write("File Content...file");
writer.close();
FileDataSource datasource = new FileDataSource(file);
attachments.setContent( new DataHandler(datasource) );
agileAddFileAttachmentRequest.getAttachments().add(attachments);

6.5.2.1 Adding attachments by File Reference

You can add an attachment to an Agile object by using a file reference for a file that has already been added to DFM. This reference is obtained from the DFM file server.

Example: Adding an attachment to a part using its file reference

agileAddFileAttachmentRequest[0].setClassIdentifier("Part");
agileAddFileAttachmentRequest[0].setObjectNumber(partNumber);
AgileAddFileAttachmentReferenceRequestType reference[] = new AgileAddFileAttachmentReferenceRequestType[1];
reference[0] = new AgileAddFileAttachmentReferenceRequestType();
reference[0].setFileId( DFMfileId );
reference[0].setFileName("FileThrowReference.txt");
reference[0].setDescription("File added using a reference");
reference[0].setFileSize( new Long(1) );
agileAddFileAttachmentRequest[0].setAttachmentRefs(reference);
addFileAttachmentRequestType.setRequests(agileAddFileAttachmentRequest);

6.5.2.2 Adding Multiple Attachments into Single Folder

Addition of several file attachments to an Agile object requires explicit specification that all the files added to the Agile object must be added to a single folder. The 'singleFolder' element specifies that all the attachments added to the object must be added under a single folder.

Example: Adding multiple attachments into a single folder

AddFileAttachmentRequestType addFileAttachmentRequestType = new AddFileAttachmentRequestType();
AgileAddFileAttachmentRequest agileAddFileAttachmentRequest = new AgileAddFileAttachmentRequest();
agileAddFileAttachmentRequest = new AgileAddFileAttachmentRequest();
agileAddFileAttachmentRequest.setClassIdentifier("Part");
agileAddFileAttachmentRequest.setObjectNumber(partNumber);
AgileAddFileAttachmentRequestType attachments[] = new AgileAddFileAttachmentRequestType[2];
File file = File.createTempFile("Filename", "txt");
FileWriter writer = new FileWriter(file);
writer.write("File Content...file");
writer.close();
FileDataSource datasource = new FileDataSource(file);
for(int i=0; i<attachments.length; i++){
attachments[i] = new AgileAddFileAttachmentRequestType();
attachments[i].setName("Filename" + (i+1) + ".txt");
attachments[i].setDescription("Description for file " + (i+1) );
attachments[i].setContent( new DataHandler(datasource) );
}
agileAddFileAttachmentRequest.getAttachments().addAll(Arrays.asList(attachments));
agileAddFileAttachmentRequest.setSingleFolder(true);
addFileAttachmentRequestType.getRequests().add(agileAddFileAttachmentRequest);

Note:

Attachment web service supports Message Transmission Optimization Mechanism (MTOM). The user can upload large files, if the security policy is not enabled. With the security policy enabled, you are limited to uploading or downloading files upto size 100M.

6.5.3 Checking Out the Attachments

Checking out an Attachment entails obtaining the file information and making changes to the same. The file information is also obtained in the response as an array of bytes. Checking out an attachment for any modifications is carried out with the checkOutAttachment operation.

Example: Checking Out an attachment of a Part

agileCheckOutAttachmentRequestType[0].setClassIdentifier("Part");
agileCheckOutAttachmentRequestType[0].setObjectNumber(partNumber);
CheckOutAttachmentType attachments[] = new CheckOutAttachmentType[1];
attachments[0] = new CheckOutAttachmentType();
attachments[0].setRowId(rowId);
agileCheckOutAttachmentRequestType[0].setAttachments(attachments);
checkOutAttachmentRequestType.setRequests(agileCheckOutAttachmentRequestType);

6.5.3.1 Checking Out All the Attachments

You can check out all the attachments of an object by setting the Boolean value of allFiles variable.

Example: Checking Out all the attachments of a Part

agileCheckOutAttachmentRequestType[0].setClassIdentifier("Part");
agileCheckOutAttachmentRequestType[0].setObjectNumber( partNumber );
agileCheckOutAttachmentRequestType[0].setAllFiles(true);
CheckOutAttachmentType attachments[] = new CheckOutAttachmentType[1];
attachments[0] = new CheckOutAttachmentType();
agileCheckOutAttachmentRequestType[0].setAttachments(attachments);
checkOutAttachmentRequestType.setRequests(agileCheckOutAttachmentRequestType);

6.5.3.2 Checking Out Multiple Attachments from a Folder

When multiple files are associated with a single row, the attachment is identified by using its rowId with the rowId of the attachment in the files tab of the file folder object. It requires usage of the rowId of the attachment along with its fileId to distinguish the attachment from all the other attachments in that row.

Example: Checking Out multiple attachments of a Part

agileCheckOutAttachmentRequestType[0].setClassIdentifier("Part");
agileCheckOutAttachmentRequestType[0].setObjectNumber( partNumber );
CheckOutAttachmentType attachments[] = new CheckOutAttachmentType[1];
attachments[0] = new CheckOutAttachmentType();
attachments[0].setRowId(rowId);
int fileIds[] = new int[] {fileId};
attachments[0].setFiles(fileIds);
agileCheckOutAttachmentRequestType[0].setAttachments(attachments);
checkOutAttachmentRequestType.setRequests(agileCheckOutAttachmentRequestType);

6.5.4 Checking In the Attachments

You can Check-In a file attachment of an Agile object after it has undergone any modifications using the operation checkInAttachment. The attachment must be checked out before the 'check in' operation.

Example: Checking In an attachment to a Part

CheckInAttachmentRequestType checkInAttachmentRequestType = new CheckInAttachmentRequestType();

AgileCheckInAttachmentRequestType agileCheckInAttachmentRequestType = new AgileCheckInAttachmentRequestType();
agileCheckInAttachmentRequestType.setClassIdentifier("Part");
agileCheckInAttachmentRequestType.setObjectNumber(partNumber);
CheckInAttachmentType attachments = new CheckInAttachmentType();                                        
attachments = new CheckInAttachmentType();
File file = File.createTempFile("Filename", "txt");
FileWriter writer  = new FileWriter(file);
writer.write("Modified file information added after the checkin");
writer.close();
FileDataSource datasource = new FileDataSource(file);
attachments.setFileContent(new DataHandler(datasource));
attachments.setFileName("Modified_" + fileName);
agileCheckInAttachmentRequestType[0].setAttachments(attachments);
agileCheckInAttachmentRequestType[0].setRowId(rowId);
checkInAttachmentRequestType.setRequest(agileCheckInAttachmentRequestType);

6.5.4.1 Checking In an Attachment with FileId Identification

In the normal course of usage, rowId will prove to be sufficient in identifying the file. However, if the file that has been checked out is part of a row that contains multiple files, then fileId is essential to identify that particular file. For such cases, you must use its fileId with its rowId.

Example: Checking In an attachment using Field ID.

CheckInAttachmentRequestType checkInAttachmentRequestType = new CheckInAttachmentRequestType();
AgileCheckInAttachmentRequestType agileCheckInAttachmentRequestType = new AgileCheckInAttachmentRequestType();
agileCheckInAttachmentRequestType.setClassIdentifier("Part");
agileCheckInAttachmentRequestType.setObjectNumber(partNumber);
CheckInAttachmentType attachments = new CheckInAttachmentType();                                        
attachments = new CheckInAttachmentType();
attachments.setFileName("Modified_" + fileName[0]);
File file = File.createTempFile("Filename", "txt");
FileWriter writer  = new FileWriter(file);
writer.write("Modified file information added after the checkin");
writer.close();
FileDataSource datasource = new FileDataSource(file);
attachments.setFileContent(new DataHandler(datasource) );
attachments.setFileId(fileId);
agileCheckInAttachmentRequestType.getAttachments().add(attachments);
agileCheckInAttachmentRequestType.setRowId(rowId);
checkInAttachmentRequestType.setRequest(agileCheckInAttachmentRequestType);

6.5.5 Deleting the Attachments

Deleting an attachment is carried out using the operation removeRows.

For examples, see "Removing Rows from a Table."