Topic
  • 4 replies
  • Latest Post - ‏2013-10-30T13:14:18Z by NKatic
IvanSaavedra
IvanSaavedra
30 Posts

Pinned topic Import - Documment Whit The Same name Of a Existing Documment

‏2013-10-17T19:14:04Z |

Hi All!

 

Is there any way to restrict the user to import a documment with the same name and properties of a documment that already exist in the ICN repository?

 

Tks a lot!

  • BJOwings
    BJOwings
    185 Posts

    Re: Import - Documment Whit The Same name Of a Existing Documment

    ‏2013-10-18T18:42:28Z  

    Are you working with CM or P8?   If this is CM then you can use the unique setting on the attribute of the item type.   I don't see a similar setting for a P8 property.  ICN doesn't have any feature to enforce uniqueness outside of the repository's.  It would be possible to add this through a programming customization, either a server-side event or ICN plugin, but it would have performance implications.  A search on document title would need to be performed on every import.

  • nicolas.leralle
    nicolas.leralle
    102 Posts

    Re: Import - Documment Whit The Same name Of a Existing Documment

    ‏2013-10-22T11:37:25Z  

    Hi Ivan,

     

    I had to implement this behavior with IBM FileNet P8.

     

    We used a synchronous subscription to handle this point.

    Here are the consideration you have to be aware of:

    • Versionning
      • Can two version of the same document have the same DocumentTitle?
      • Have I to test the unicity on current version of document, or all version
    • Security rights (How can I notify the user that a document with the same Title exists, if he has no access to it?)

     

    We choose to implement following rules:

    • DocumentTitle has to be unique against all documents versions
    • If an existing value is found, if it is the same document, but an other version, the DocumentTitle is allowed, else, even if the user can't see the document, an exception is thrown, blocking the document add.

     

    The sample code looks like:

     

    private void checkDocTitleUnicity(Document docToCheck) {
    String documentTitle = docToCheck.get_Name();
    String documentId = docToCheck.get_Id().toString();
    String documentVersionSeriesId = docToCheck.get_VersionSeries().get_Id().toString();
    SearchScope searchScope = new SearchScope(objectStore);
    // Instantiate an SQL object to hold our search criteria
    SearchSQL search = new SearchSQL();
    // When searching, retrieve certain property
    search.setSelectList("Id");
    // From certain class
    search.setFromClauseInitialValue("Document", "D", true);
    documentTitle = documentTitle.replaceAll("'", "''");
    // with certain restrictions
    search.setWhereClause("DocumentTitle='"+documentTitle+"'");
    try{
    RepositoryRowSet rowSet = searchScope.fetchRows(search, null, null, new Boolean(true));
    Iterator<RepositoryRow> iter = rowSet.iterator();
    while (iter.hasNext()) {
    RepositoryRow row = (RepositoryRow) iter.next();
    Document docResult = Factory.Document.fetchInstance(objectStore, row.getProperties().get("Id").getIdValue(), null);
    if(!docResult.get_VersionSeries().get_Id().toString().equalsIgnoreCase(documentVersionSeriesId)){
    throw new EngineRuntimeException(ExceptionCode.E_NOT_UNIQUE);
    }
    }
    }catch (EngineRuntimeException ere) {
    if(!ere.getExceptionCode().equals(ExceptionCode.E_NOT_UNIQUE)){
    logger.error("Unmanaged exception occured during search : "+ere.getMessage());
    ErrorRecord er[] = { new ErrorRecord(ere) };
    throw new EngineRuntimeException(ere, ExceptionCode.EVENT_HANDLER_THREW, er);
    }
    else
    throw ere;
    }catch (Exception e) {
    logger.error("Unmanaged exception occured during search : "+e.getMessage());
    ErrorRecord er[] = { new ErrorRecord(e) };
    throw new EngineRuntimeException(e, ExceptionCode.EVENT_HANDLER_THREW, er);
    }
    logger.info("The document title "+documentTitle+" for the document with ID {"+documentId+"} is unique");
    }

     

    Hope this helps.

    Best regards,

     

    Nicolas

  • IvanSaavedra
    IvanSaavedra
    30 Posts

    Re: Import - Documment Whit The Same name Of a Existing Documment

    ‏2013-10-30T12:30:09Z  

    Hi Ivan,

     

    I had to implement this behavior with IBM FileNet P8.

     

    We used a synchronous subscription to handle this point.

    Here are the consideration you have to be aware of:

    • Versionning
      • Can two version of the same document have the same DocumentTitle?
      • Have I to test the unicity on current version of document, or all version
    • Security rights (How can I notify the user that a document with the same Title exists, if he has no access to it?)

     

    We choose to implement following rules:

    • DocumentTitle has to be unique against all documents versions
    • If an existing value is found, if it is the same document, but an other version, the DocumentTitle is allowed, else, even if the user can't see the document, an exception is thrown, blocking the document add.

     

    The sample code looks like:

     

    private void checkDocTitleUnicity(Document docToCheck) {
    String documentTitle = docToCheck.get_Name();
    String documentId = docToCheck.get_Id().toString();
    String documentVersionSeriesId = docToCheck.get_VersionSeries().get_Id().toString();
    SearchScope searchScope = new SearchScope(objectStore);
    // Instantiate an SQL object to hold our search criteria
    SearchSQL search = new SearchSQL();
    // When searching, retrieve certain property
    search.setSelectList("Id");
    // From certain class
    search.setFromClauseInitialValue("Document", "D", true);
    documentTitle = documentTitle.replaceAll("'", "''");
    // with certain restrictions
    search.setWhereClause("DocumentTitle='"+documentTitle+"'");
    try{
    RepositoryRowSet rowSet = searchScope.fetchRows(search, null, null, new Boolean(true));
    Iterator<RepositoryRow> iter = rowSet.iterator();
    while (iter.hasNext()) {
    RepositoryRow row = (RepositoryRow) iter.next();
    Document docResult = Factory.Document.fetchInstance(objectStore, row.getProperties().get("Id").getIdValue(), null);
    if(!docResult.get_VersionSeries().get_Id().toString().equalsIgnoreCase(documentVersionSeriesId)){
    throw new EngineRuntimeException(ExceptionCode.E_NOT_UNIQUE);
    }
    }
    }catch (EngineRuntimeException ere) {
    if(!ere.getExceptionCode().equals(ExceptionCode.E_NOT_UNIQUE)){
    logger.error("Unmanaged exception occured during search : "+ere.getMessage());
    ErrorRecord er[] = { new ErrorRecord(ere) };
    throw new EngineRuntimeException(ere, ExceptionCode.EVENT_HANDLER_THREW, er);
    }
    else
    throw ere;
    }catch (Exception e) {
    logger.error("Unmanaged exception occured during search : "+e.getMessage());
    ErrorRecord er[] = { new ErrorRecord(e) };
    throw new EngineRuntimeException(e, ExceptionCode.EVENT_HANDLER_THREW, er);
    }
    logger.info("The document title "+documentTitle+" for the document with ID {"+documentId+"} is unique");
    }

     

    Hope this helps.

    Best regards,

     

    Nicolas

    Nicolas,

    Hi!

     

    Tks very much for the answer and sorry for this basic question, but, where can I implement this code?

     

    Seeing another topic on this forum, you say to export a code module to the content engine server. Is that right? If it is, how can I do that?

     

    Tks a lot!

     

    Ivan Saavedra

     

  • NKatic
    NKatic
    11 Posts

    Re: Import - Documment Whit The Same name Of a Existing Documment

    ‏2013-10-30T13:14:18Z  

    Nicolas,

    Hi!

     

    Tks very much for the answer and sorry for this basic question, but, where can I implement this code?

     

    Seeing another topic on this forum, you say to export a code module to the content engine server. Is that right? If it is, how can I do that?

     

    Tks a lot!

     

    Ivan Saavedra

     

    Hi Ivan,

    Have a look to the FileNet documentation : 

    Concepts: http://pic.dhe.ibm.com/infocenter/p8docs/v5r2m0/index.jsp?topic=%2Fcom.ibm.p8.ce.dev.ce.doc%2Fsubscription_concepts.htm

    Implementation : http://pic.dhe.ibm.com/infocenter/p8docs/v5r2m0/index.jsp?topic=%2Fcom.ibm.p8.ce.dev.ce.doc%2Fserver_procedures.htm

     

    You'll find all answer there.

     

    Best regards,

     

    Nathan