In this session am going to walk you through how to create a custom Action for ICN 2.0.3 version using IBM Plugin.
Use Case Scenario:
Usually any document in the filenet repository will be added by using AddDocument Action from the ToolBar Menu then you would add document by giving some title to the document,
in our scenario when document is added with the same name of any other document already resides in repository we need to give caution to user that document is already added in the repository.
We are going to develop this custom
SearchBase AddDocument Action button using IBM plugin.
Starting Code:
I will take you through each and every step from the start point to endpoint of whole development process.
1:Creating Plugin Project
--Open Up your Eclipse create new IBM Content navigator Plugin
--Give project name and package name,Navigator.jar location and click on next until it says finish.
--Right click on project create new Action Name it as
searchBasedAddDocument click on finish.
Now lets start actual coding part.
2.After you create action eclipse creates a "
searchBase AddDocument" Attach point in .js file .
3.To add any document we need a contentPane that allows a user to add document this can be achieved by calling AddContentItemDialog object ,this can be created as follows
define("Add Content Item Dialog",function(adddialog))
{
var current=this;
current=new adddialog();
}
//here current is an object of AddContentItemDialog ,now lets open dialog (you can do this by calling current.show())
current.show(repository,items[0],true,false,null,teamspace,false,null);
4.Once you had dialog content pane ,you can get all the properties of document by using current.addContentItemPropertiesPane.getPropertiesJSON() call this gives you all properties of document.
then get the document title and search against repository the result will be ecm.model.ResultSet object representing set of Objects Items.if we had any objectItem from the result it means there is a document presented already in repository so we need to give an alert to user .
//see the whole code that implemented for the Action.
require(["dojo/_base/declare",
"dojo/_base/lang",
"ecm/widget/dialog/AddContentItemDialog",
"ecm/model/SearchQuery",
"ecm/widget/AddContentItemPropertiesPane",
"ecm/model/Request",
"ecm/widget/dialog/ConfirmationDialog"],
function(declare, lang,adddialog,searchquery,contentItem,requestobj,ConfirmationDialog) {
/**
* Use this function to add any global JavaScript methods your plug-in requires.
*/
lang.setObject("searchBase AddDocument", function(repository, items, callback, teamspace, resultSet, parameterMap) {
/*
* Add custom code for your action here. For example, your action might launch a dialog or call a plug-in service.
*/
var documentname;
var current=this;
current=new adddialog();
var content=new contentItem();
current.show(repository,items[0],true,false,null,teamspace,false,null);
current.onAdd=function(){
//get the item id
//get item document title
content.setAddContentItemDialog(current);
var properties = current.addContentItemPropertiesPane.getPropertiesJSON();
alert(properties);
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
var val = properties[key];
if(val.name==="DocumentTitle"){
documentname=val.value;
}
console.log("Object name is"+val.name+"-- Its value is "+val.value);
//console.log(val);
}
}
if(documentname!=null && documentname!==""){
var selectedClass =current.addContentItemPropertiesPane._contentClass.id;
//create a search using this template
//var ceQuery="SELECT This, DocumentTitle FROM Document WHERE DocumentTitle="+"'"+documentname+"'";
var ceQuery="SELECT This, ClassDescription, DocumentTitle FROM "+selectedClass+" WHERE DocumentTitle="+"'"+documentname+"'";
console.log("sql query is "+ceQuery);
var searchQuery = new searchquery({"pageSize":0,"query":ceQuery,"retrieveAllVersions":false,"retrieveLatestVersion":false,"repository": repository});
searchQuery.search(function(resultSet){
if(resultSet.totalCount>0){
confirm=new ConfirmationDialog(
{text: "A Document is already added in repositoty.",
buttonLabel: "OK",
title: "Confirm",
cancelButtonDefault: true,
onExecute: function() {
callMethod();
},
onCancel: function() {
cancelMethod();
}
});
confirm.show();
}
else
{
callMethod();
}
},null,null,null,function(error){
console.debug("Search error::",error);
});
}
};
function cancelMethod(){
current.destroy();
}
function callMethod(){
current._multiAddCleanup();
current._titleProperty = null;
var addAsMinorVersion = !current.addContentItemGeneralPane.getAsMajorVersion();
var autoClassify = current.addContentItemGeneralPane.getAutoClassify();
var compoundDocument = current._entryTemplate && current._entryTemplate.enableCompoundDocuments && current._entryTemplate.enableCompoundDocuments.on ? true : false;
var documentType = current.addContentItemPropertiesPane.getDocumentType();
var properties = current.addContentItemPropertiesPane.getPropertiesJSON();
var childComponentValues = current.addContentItemPropertiesPane.getChildComponentValues();
var permissions = current.addContentItemSecurityPane.getPermissions();
var allowDuplicateFileNames = true;
current._multiAddProcessing = current.addContentItemGeneralPane.hasMultipleDocuments();
var teamspaceId;
if (current._entryTemplate) {
allowDuplicateFileNames = current._entryTemplate.allowDuplicateFileNames;
}
if (current._teamspace && current._useTeamspaceACL) {
// Pass the teamspace id so the ACL of the teamspace can be applied.
teamspaceId = current._teamspace.id;
}
if (current._typeDocument) {
var setSecurityParent = (current._teamspace && current.repository._isP8());
if (!setSecurityParent && current._entryTemplate && current._entryTemplate.inheritSecurityFromParentFolder) {
setSecurityParent = true;
}
var contentSourceType = current.addContentItemGeneralPane.getContentSourceType();
var inputFiles = current.addContentItemGeneralPane.getFileInputFiles();
// If there are input files... (HTML5 browser).
if (inputFiles) {
current._documentItems = [];
if ((contentSourceType == "Document") && (inputFiles.length > 0)) {
if (current._multiAddProcessing) {
// Start the batch status dialog as modal until the first add succeeds.
current._createBatchStatusDialog(false);
// When adding multiple documents, use the file name for the title - except if current is a CM repository
// and the title property is not "ICM$NAME".
current._multiAddAssignFileNameProperty = null;
var titlePropertyName = current.addContentItemPropertiesPane.getTitlePropertyName();
if (titlePropertyName && (!current.repository._isCM() || (titlePropertyName == "ICM$NAME"))) {
array.some(properties, lang.hitch(current, function(property) {
if (property.name == titlePropertyName) {
current._multiAddAssignFileNameProperty = property;
return false;
}
}));
}
current._multiAddFileCount = 0;
current._multiAddNumFiles = inputFiles.length;
}
for (var i = 0; i < inputFiles.length; i++) {
var file = inputFiles[i];
var documentItem = {
"templateName": documentType,
"teamspaceId": teamspaceId,
"contentSourceType": contentSourceType,
"mimetype": file.type,
"filename": (file.fileName != null) ? file.fileName : file.name,
filePath: (file.filePath != null) ? file.filePath : null,
"securityPolicyId": current._getSecurityPolicyId(),
"addAsMinorVersion": addAsMinorVersion,
"autoClassify": autoClassify,
"compoundDocument": compoundDocument,
"allowDuplicateFileNames": allowDuplicateFileNames,
"setSecurityParent": setSecurityParent
};
// IE10 and IE11 will hang when uploading a zero size file unless an IFRAME is used.
// At current time, IE10 and IE11 will still hang if multiple documents are added and one is a zero-size file.
if (has("trident") && file.size == 0) {
// Retrieve references to the form fields and set the data.
var propertiesInput = current.addContentItemGeneralPane._getPropertiesInput();
propertiesInput.value = dojojson.toJson(properties);
var childComponentInput = current.addContentItemGeneralPane._getChildComponentInput();
childComponentInput.value = dojojson.toJson(childComponentValues);
var permissionsInput = current.addContentItemGeneralPane._getPermissionsInput();
permissionsInput.value = dojojson.toJson(permissions);
lang.mixin(documentItem, {
"inputForm": current.addContentItemGeneralPane.getFileInputForm()
});
} else {
lang.mixin(documentItem, {
"criterias": properties,
"content": file,
"childComponentValues": childComponentValues,
"permissions": permissions
});
}
current._documentItems.push(documentItem);
}
} else { // Adding without file content.
var fileName = (contentSourceType == "ExternalURL") ? current.addContentItemGeneralPane.getExternalURL() : null;
current._documentItems.push({
"templateName": documentType,
"teamspaceId": teamspaceId,
"criterias": properties,
"contentSourceType": contentSourceType,
"mimetype": null,
"filename": fileName,
"content": null,
"childComponentValues": childComponentValues,
"permissions": permissions,
"securityPolicyId": current._getSecurityPolicyId(),
"addAsMinorVersion": addAsMinorVersion,
"autoClassify": autoClassify,
"compoundDocument": compoundDocument,
"allowDuplicateFileNames": allowDuplicateFileNames,
"setSecurityParent": setSecurityParent
});
}
} else { // current browser does not support HTML5.
// Retrieve references to the form fields and set the data.
var propertiesInput = current.addContentItemGeneralPane._getPropertiesInput();
propertiesInput.value = dojojson.toJson(properties);
var childComponentInput = current.addContentItemGeneralPane._getChildComponentInput();
childComponentInput.value = dojojson.toJson(childComponentValues);
var permissionsInput = current.addContentItemGeneralPane._getPermissionsInput();
permissionsInput.value = dojojson.toJson(permissions);
var fileName;
if (contentSourceType == "Document") {
fileName = current.addContentItemGeneralPane.getInputFileName();
} else if (contentSourceType == "ExternalURL") {
fileName = current.addContentItemGeneralPane.getExternalURL();
} else {
fileName = null;
}
current._documentItems = [
{
"templateName": documentType,
"teamspaceId": teamspaceId,
"contentSourceType": contentSourceType,
"filename": fileName,
"inputForm": current.addContentItemGeneralPane.getFileInputForm(),
"securityPolicyId": current._getSecurityPolicyId(),
"addAsMinorVersion": addAsMinorVersion,
"autoClassify": autoClassify,
"compoundDocument": compoundDocument,
"allowDuplicateFileNames": allowDuplicateFileNames,
"setSecurityParent": setSecurityParent
}
];
}
current._addDocumentItemMultiple();
} else {
// Ignore additional attempts to add current folder if it is already being added.
if (current._addingFolder) {
return;
}
current._addingFolder = true;
var folderName;
var folderProperties = {};
folderName = current.addContentItemPropertiesPane.getItemName();
folderProperties.folderName = folderName;
folderProperties.docid = current.parentFolder ? current.parentFolder.id : "";
folderProperties.criterias = properties;
folderProperties.childComponentValues = childComponentValues;
folderProperties.documentType = documentType;
if (current._virtualItems) {
if (current._isValidFolderName(folderName)) {
current.addFolderInMemory(folderProperties);
}
delete current._addingFolder;
return;
}
var request;
var onAddFolderRequestCompletedHandler = aspect.after(ecm.model.desktop, "onRequestCompleted", lang.hitch(current, function(completedRequest) {
if (!request || !request.isSameRequestAs(completedRequest)) {
return;
}
delete current._addingFolder;
onAddFolderRequestCompletedHandler.remove();
}), true);
var parentFolder = current.parentFolder;
if (current.repository._isP8()) {
var objectStore = (parentFolder && parentFolder.objectStore);
if (!objectStore && current._objectStore) {
objectStore = current._objectStore;
}
request = current.repository.addFolderItem(parentFolder, objectStore, documentType, folderProperties, [], permissions, current._getSecurityPolicyId(), teamspaceId, lang.hitch(current, current._addFolderItemCallback));
} else {
request = current.repository.addFolderItem(parentFolder, null, documentType, properties, childComponentValues, permissions, null, teamspaceId, lang.hitch(current, current._addFolderItemCallback));
}
if (!request) {
if (onAddFolderRequestCompletedHandler) {
onAddFolderRequestCompletedHandler.remove();
}
delete current._addingFolder;
}
}
}
});
});
5.create a jar file using Ant or any other tool by which you are familiar.
6.Now add this plugin to navigator As shown in below
6.1.Open your navigator desktop in Administrator mode
6.2.open Plugins from context menu
6.3.create a new plugin and give the jar file path thats it.you can able to see your custom action in Context Menus if you add these Action in Menus. (To test this Action i was added this action to Folder Context Menu)
Run ScreenShots:
1.Opening Folder Context Action
2.Am adding a document with title which is already presented in the repository.(You might expect a alert ).
Thank you very much if you like please share this link .
If you want to download entire source code please click on below add link that will automatically redirects you to download page.