Thứ Tư, 16 tháng 11, 2016

Add value to datatype multil ibm case manager



var coord = payload.coordination;
var workitemEdit = payload.workItemEditable;
var solution = this.solution;
var prefix = solution.getPrefix();

require(["icm/base/Constants", "icm/model/properties/controller/ControllerManager"], 
function(Constants, ControllerManager){

if(coord){

/*Participate in the VALIDATE cordination step*/

coord.participate(Constants.CoordTopic.VALIDATE, function(context, complete, abort){

/*Check the specific response, an empty string ("") stands for the Complete button*/

if(context[Constants.CoordContext.WKITEMRESPONSE] === "Apporve")
{

   /*Check work item property attribute's value*/

  

   /*Retrieve prop value using property controller API*/

   /*Unbind is necessary to prevent mem leak.*/
var propsControllerSTT = ControllerManager.bind(workitemEdit);
console.log(" :", propsControllerSTT);
var controllerSTT = propsControllerSTT.getPropertyController("F_CaseFolder.DOL_STT");
console.log(" :", controllerSTT);
var arrValue = controllerSTT.get("value");
//var choicesSTT = [];
arrValue.push("1");
arrValue.push("2");
arrValue.push("3");
arrValue.push("10");
arrValue.push("15");
arrValue.push("20");
console.log(": choicesSTT ", arrValue);
controllerSTT.set("value", arrValue); 
console.log(": set value ok ");
var propsControllerMota = ControllerManager.bind(workitemEdit);
var controllerMota = propsControllerMota.getPropertyController("F_CaseFolder.DOL_Mota");
var arrValuemota = controllerMota.get("value");
//var choicesDes = [];
arrValuemota.push("xxx");
arrValuemota.push("xxx");
arrValuemota.push("xxxxx");
arrValuemota.push("xxxxx");
arrValuemota.push("xxxx");
arrValuemota.push("xxxxx");
console.log(": choicesDes ", arrValuemota);
controllerMota.set("value", arrValuemota);
console.log(": set value ok 2");
   
   
   ControllerManager.unbind(workitemEdit);

   
     complete();
   
 }else
 {
    complete();
 }
 });
}
});

Thứ Hai, 10 tháng 10, 2016

JAAS - J2C authentication data in websphere


  Map map = new HashMap();
    map.put(Constants.MAPPING_ALIAS,"TEST-ECM-CMNode01/ecm_admin");
    CallbackHandler callbackHandler = WSMappingCallbackHandlerFactory.getInstance().getCallbackHandler(map, null);

    LoginContext loginContext = new LoginContext("DefaultPrincipalMapping", callbackHandler);
    loginContext.login();

    Subject subject_1 = loginContext.getSubject();
    Set credentials = subject_1.getPrivateCredentials();

    PasswordCredential passwordCredential = (PasswordCredential) credentials.iterator().next();

    String username = passwordCredential.getUserName();
    String password = new String(passwordCredential.getPassword());

Chủ Nhật, 9 tháng 10, 2016

Java Properties file examples


Normally, Java properties file is used to store project configuration data or settings. In this tutorial, we will show you how to read and write to/from a properties file.

1. Write to properties file

Set the property value, and write it into a properties file named config.properties.
App.java
package com.mkyong.properties;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;

public class App {
  public static void main(String[] args) {

 Properties prop = new Properties();
 OutputStream output = null;

 try {

  output = new FileOutputStream("config.properties");

  // set the properties value
  prop.setProperty("database", "localhost");
  prop.setProperty("dbuser", "mkyong");
  prop.setProperty("dbpassword", "password");

  // save properties to project root folder
  prop.store(output, null);

 } catch (IOException io) {
  io.printStackTrace();
 } finally {
  if (output != null) {
   try {
    output.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }

 }
  }
}
Output
config.properties
#Fri Jan 17 22:37:45 MYT 2014
dbpassword=password
database=localhost
dbuser=mkyong
P.S If file path is not specified, then this properties file will be stored in your project root folder.

2. Load a properties file

Load a properties file from the file system and retrieved the property value.
App.java
package com.mkyong.properties;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class App {
  public static void main(String[] args) {

 Properties prop = new Properties();
 InputStream input = null;

 try {

  input = new FileInputStream("config.properties");

  // load a properties file
  prop.load(input);

  // get the property value and print it out
  System.out.println(prop.getProperty("database"));
  System.out.println(prop.getProperty("dbuser"));
  System.out.println(prop.getProperty("dbpassword"));

 } catch (IOException ex) {
  ex.printStackTrace();
 } finally {
  if (input != null) {
   try {
    input.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

  }
}
Output
localhost
mkyong
password

3. Load a properties file from classpath

Load a properties file config.properties from project classpath, and retrieved the property value.
P.S Assume properties file “config.properties” is in your project classpath root folder.
App.java
package com.mkyong.properties;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class App {

  public static void main( String[] args ){

     Properties prop = new Properties();
     InputStream input = null;

     try {

      String filename = "config.properties";
      input = App3.class.getClassLoader().getResourceAsStream(filename);
      if(input==null){
                 System.out.println("Sorry, unable to find " + filename);
          return;
      }

      //load a properties file from class path, inside static method
      prop.load(input);

                //get the property value and print it out
                System.out.println(prop.getProperty("database"));
             System.out.println(prop.getProperty("dbuser"));
             System.out.println(prop.getProperty("dbpassword"));

     } catch (IOException ex) {
      ex.printStackTrace();
        } finally{
         if(input!=null){
          try {
    input.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
         }
        }

    }
}
Output
localhost
mkyong
password
For non-static method, use this :
prop.load(getClass().getClassLoader().getResourceAsStream("config.properties"));

4. Prints everything from a properties file

Load a properties file config.properties from project classpath, and get the keys and values.
App.java
package com.mkyong.properties;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

public class App {

  public static void main(String[] args) {
 App app = new App();
 app.printThemAll();
  }

  private void printThemAll() {

 Properties prop = new Properties();
 InputStream input = null;

 try {

  String filename = "config.properties";
  input = getClass().getClassLoader().getResourceAsStream(filename);
  if (input == null) {
   System.out.println("Sorry, unable to find " + filename);
   return;
  }

  prop.load(input);

  Enumeration<?> e = prop.propertyNames();
  while (e.hasMoreElements()) {
   String key = (String) e.nextElement();
   String value = prop.getProperty(key);
   System.out.println("Key : " + key + ", Value : " + value);
  }

 } catch (IOException ex) {
  ex.printStackTrace();
 } finally {
  if (input != null) {
   try {
    input.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

  }

}
Output
Key : dbpassword, Value : password
Key : database, Value : localhost
Key : dbuser, Value : mkyong

Create job for application java 


package java.job;


import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;


public class testjob implements Job 
{
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
try {
testSchedule();
} catch (Exception e) {
System.out.println("execute error: " + e.toString());
}

}

private void testSchedule() 
{
System.out.println("test schedule =============================");
}

}

===============================================

package ecm.job;

import java.util.Date;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;


public class SimpleTriggerExample {
public static void main(String[] args) throws Exception {
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
JobDetail job = new JobDetail();
job.setName("dummyJobName");    
job.setJobClass(testjob.class);
 
//configure the scheduler time
SimpleTrigger trigger = new SimpleTrigger();
trigger.setName("dummyTriggerName");    
trigger.setStartTime(new Date(System.currentTimeMillis()));
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);

trigger.setRepeatInterval(1000*30); //setup 30'
 
//schedule it
scheduler.start();
scheduler.scheduleJob(job, trigger);

}
}

Get and Put properties on Document


   ObjectStore objectstore =//Get Object Store
                logger.info("Object Store Name :: "+objectstore.get_DisplayName());
                SearchScope search=new SearchScope(objectstore);
                String value = "abcd"
                String sql1= "Select * from DocumentClass where DocumentTitle = "+value;
                SearchSQL searchSQL=new SearchSQL(sql1);
                DocumentSet documents=(DocumentSet)search.fetchObjects(searchSQL, Integer.getInteger("50"), null, Boolean.valueOf(true));
                Document doc;
                Iterator it=documents.iterator();
                while(it.hasNext())
                {
                    doc=(Document)it.next();
                    doc.getProperties().putValue("Name", abc);
                    doc.getProperties().putValue("number", 123);
                    doc.getProperties().putValue("Salary", 200);
                    doc.save(RefreshMode.REFRESH);

                } 

Searching and Deleting documents API FileNet



  SearchScope search=new SearchScope(objectstore);
                String value = abc;
                String sql1= "Select * from DocClass where DocumentTitle = "+ Value;
                SearchSQL searchSQL=new SearchSQL(sql1);
                DocumentSet documents=(DocumentSet)search.fetchObjects(searchSQL, Integer.getInteger("50"), null, Boolean.valueOf(true));
                Document doc;
                Iterator it=documents.iterator();
                while(it.hasNext())
                {
                    doc=(Document)it.next();
                    logger.info("document name::"+doc.get_Name());
                    logger.info("deleting the document now:::");
                    doc.delete();
                    doc.save(RefreshMode.REFRESH);
                    
                }

Thứ Năm, 6 tháng 10, 2016

Search CE Object using SearchSQL (Content Engine API)



package createdoc_api;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Iterator;

import javax.security.auth.Subject;
import com.filenet.api.collection.ContentElementList;
import com.filenet.api.collection.RepositoryRowSet;
import com.filenet.api.constants.AutoClassify;
import com.filenet.api.constants.AutoUniqueName;
import com.filenet.api.constants.CheckinType;
import com.filenet.api.constants.ClassNames;
import com.filenet.api.constants.DefineSecurityParentage;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.core.Connection;
import com.filenet.api.core.ContentTransfer;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Document;
import com.filenet.api.core.Factory;
import com.filenet.api.core.Folder;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.core.ReferentialContainmentRelationship;
import com.filenet.api.property.Properties;
import com.filenet.api.query.RepositoryRow;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;
import com.filenet.api.util.Id;
import com.filenet.api.util.UserContext;

public class sql_query {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub

String uri = "http://ecmdemo1.ecm.ibm.local:9080/wsi/FNCEWS40MTOM/";
    String username = "P8admin";
    String password = "filenet";
    String v_id = null;
    // Make connection.
    Connection conn = Factory.Connection.getConnection(uri);
    Subject subject = UserContext.createSubject(conn, username, password, null);
    UserContext.get().pushSubject(subject);

    try
    {
       // Get default domain.
       Domain domain = Factory.Domain.fetchInstance(conn, null, null);
       System.out.println("Domain: " + domain.get_Name());

       // Get object stores for domain.
      // ObjectStoreSet osSet = domain.get_ObjectStores();
      /// ObjectStore store;
       //Iterator osIter = osSet.iterator();

       //while (osIter.hasNext())
       ///{
        //  store = (ObjectStore) osIter.next();
        //  System.out.println("Object store: " + store.get_Name());
      // }

       System.out.println("Connection to Content Platform Engine successful");
     
    // Create a document instance.
       ObjectStore os = Factory.ObjectStore.getInstance(domain, "CMTOS");
   
       String searchQ = "SELECT ID FROM CmAcmCaseFolder WHERE LP_ID_link = 2";
     
             SearchSQL sqlObject = new SearchSQL(searchQ);
           SearchScope searchScope = new SearchScope(os);

 

       // Execute the fetchRows method using the specified parameters.
       RepositoryRowSet myRows = searchScope.fetchRows(sqlObject, null, null, new Boolean(true));

       // You can then iterate through the collection of rows to access the properties.
       int rowCount = 0;
   
       Iterator iter = myRows.iterator();
       while (iter.hasNext())
       {
           RepositoryRow row = (RepositoryRow) iter.next();
                 
         //  String docTitle = row.getProperties().get("DocumentTitle").getStringValue();
           Id docId = row.getProperties().get("Id").getIdValue();
           v_id=docId.toString();      
           rowCount++;
           System.out.print(" row " + rowCount + ":");
           System.out.print(" Id=" + docId.toString());
           //if (docTitle != null)
           //{
            //   System.out.print(" DocumentTitle=" + docTitle);
           // }
          // System.out.println();                          
        }
     
    }
    finally
    {
       UserContext.get().popSubject();
    }
    System.out.println("a"+ v_id);    
 
}

}