Author Topic: PSDK Update Object  (Read 8031 times)

Offline walter2

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: PSDK Update Object
« Reply #15 on: October 08, 2021, 03:32:52 PM »
Java method to move objects

/**
    Move existing object to new folder
    @param moveToFolder target folder Dbid
    @param movedObjectDbId moved object dbid
    @param movedObjectType moved object type
    */
    private void moveToFolder(CfgFolder moveToFolder, int movedObjectDbId , CfgObjectType movedObjectType) {
        CfgObjectID movedId = new CfgObjectID(confService, null);
        movedId.setDBID( movedObjectDbId );
        movedId.setType(movedObjectType);

        Collection<CfgObjectID> moveToFolderObjectIDs = moveToFolder.getObjectIDs();
        moveToFolderObjectIDs.add(movedId);
        moveToFolder.setObjectIDs(moveToFolderObjectIDs);
        try {
            moveToFolder.save();
        }
        catch (Exception exc){
            log.trace(String.format("Could not move object %s (dbid=%s) " +
                            "to folder %s (dbid=%s) due to the error: %s ",
                    movedObjectType, movedObjectDbId,
                    moveToFolder.getName(), moveToFolder.getDBID(), exc.getMessage() ),exc);
        }
    }