{
  "processId" : 1,
  "id" : 1,
  "name" : "Global library",
  "locked" : false,
  "version" : 1,
  "active" : true,
  "nodes" : [ {
    "id" : 1,
    "type" : "start",
    "name" : "workflow.start",
    "posX" : 100.0,
    "posY" : 100.0,
    "description" : null,
    "sourcePosition" : "bottom",
    "targetPosition" : "none",
    "transitions" : [ ],
    "script" : null,
    "form" : null,
    "assignExpr" : null,
    "dueDate" : null,
    "repeat" : null,
    "notifyAssignment" : true,
    "notificationSubject" : null,
    "notificationBody" : null,
    "recipients" : null,
    "subject" : null,
    "body" : null
  }, {
    "id" : 2,
    "type" : "action",
    "name" : "library_global_base",
    "posX" : 214.6336320923033,
    "posY" : 102.35770767712094,
    "description" : "",
    "sourcePosition" : "bottom",
    "targetPosition" : "top",
    "transitions" : [ ],
    "script" : "import com.openkm.sdk4j.impl.OKMWebservices;\nimport com.openkm.sdk4j.bean.*;\nimport com.openkm.okmflow.util.*;\nimport com.openkm.okmflow.bean.*;\nimport com.openkm.util.*;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.fasterxml.jackson.core.JsonProcessingException;\nimport com.fasterxml.jackson.databind.DeserializationFeature;\nimport java.time.LocalDateTime;\nimport java.time.Duration;\n\n// Base library with common functions that can be used by all libraries\nclass BaseLibrary {\n    \n    static void logInfo(String component, String message) {\n        FileLogger.info(component, message);\n    }\n    \n    static void logError(String component, String message, Exception e = null) {\n        FileLogger.error(component, message + \"\\n\" + StackTraceUtils.toString(e));\n    }\n    \n    static OKMWebservices getWebservices() {\n        logInfo(\"BaseLibrary\", \"getWebservices\");\n        return WebservicesHelper.getInstance();\n    }\n    \n    static Object getContextValue(Map<String,Object> context, String key) {\n        logInfo(\"BaseLibrary\", \"getContextValue\");\n        return context.get(key);\n    }\n    \n    static void setContextValue(Map<String,Object> context, String key, Object value) {\n        logInfo(\"BaseLibrary\", \"setContextValue\");\n        context.put(key, value);\n    }\n\n    // Get workflow initiator ID\n    static String getInitiatorId(Map<String,Object> context) {\n        logInfo(\"BaseLibrary\", \"getInitiatorId\");\n        Actor actor = context.get(\"initiator\");\n        return actor.getId();\n    }\n\n    // Get workflow initiator ID\n    static long getProcessInstanceId(Map<String,Object> context) {\n        logInfo(\"BaseLibrary\", \"getProcessInstanceId\");\n        def procIns = context.get(\"processInstance\");\n        return procIns.getId();\n    }\n\n    static String convertToJson(Object obj) {\n        try {\n          ObjectMapper objectMapper = new ObjectMapper();\n          return objectMapper.writeValueAsString(obj);\n        } catch (JsonProcessingException e) {\n          logError(\"BaseLibrary\", \"Error converting object to JSON\", e);\n          throw e;\n        }\n    }\n\n  static <T> T convertFromJson(String jsonString, Class<T> targetClass) {\n        try {\n            ObjectMapper objectMapper = new ObjectMapper();\n            objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);\n            return objectMapper.readValue(jsonString, targetClass);\n        } catch (JsonProcessingException e) {\n            logError(\"BaseLibrary\", \"Error converting JSON to object of type: \" + targetClass.getSimpleName(), e);\n            throw e;\n        } catch (IllegalArgumentException e) {\n            logError(\"BaseLibrary\", \"Invalid JSON string or target class\", e);\n            throw e;\n        }\n    }\n  static boolean hasDurationElapsed(String durationString, LocalDateTime startTime) {\n        try {\n            // Parse the ISO 8601 duration string\n            Duration expectedDuration = Duration.parse(durationString);\n            \n            // Get current time\n            LocalDateTime currentTime = LocalDateTime.now();\n            \n            // Calculate actual elapsed time since start time\n            Duration elapsedDuration = Duration.between(startTime, currentTime);\n            \n            // Check if elapsed time is greater than or equal to expected duration\n            return elapsedDuration.compareTo(expectedDuration) >= 0;\n            \n        } catch (Exception e) {\n            logError(\"BaseLibrary\", e.getMessage(), e);\n            throw e;\n        }\n    }\n}\n\nreturn BaseLibrary",
    "form" : null,
    "assignExpr" : null,
    "dueDate" : null,
    "repeat" : null,
    "notifyAssignment" : true,
    "notificationSubject" : null,
    "notificationBody" : null,
    "recipients" : null,
    "subject" : null,
    "body" : null
  }, {
    "id" : 3,
    "type" : "action",
    "name" : "library_global_document",
    "posX" : 215.46242191108445,
    "posY" : 188.70012803955856,
    "description" : "",
    "sourcePosition" : "bottom",
    "targetPosition" : "top",
    "transitions" : [ ],
    "script" : "import com.openkm.sdk4j.impl.OKMWebservices;\nimport com.openkm.sdk4j.bean.*;\nimport com.openkm.okmflow.util.*;\nimport com.openkm.okmflow.bean.*;\nimport com.openkm.util.*;\nimport java.util.*;\n\n// Declare binding variables to avoid validation errors\ndef BaseLibrary = BaseLibrary  // Will be provided by binding\n\ndef rename(Map<String, String> context, String newName) {\n  BaseLibrary.logInfo(\"GlobalDocumentLibrary\", \"rename\");\n  String uuid = BaseLibrary.getContextValue(context, \"uuid\");\n  OKMWebservices ws = BaseLibrary.getWebservices();\n  String path = ws.repository.getNodePath(uuid);\n  String docName = PathUtils.getName(path);\n  String fileName = FileUtils.getFileName(docName);\n  int dashIndex = fileName.indexOf(\"-\");\n  fileName = (dashIndex >= 0) ? fileName.substring(0, dashIndex) : fileName;\n  String fileExtension = FileUtils.getFileExtension(docName);\n  newName = fileName + \"-\" + newName + \".\" + fileExtension;\n  ws.document.rename(uuid, newName);\n}\n\nreturn this;",
    "form" : null,
    "assignExpr" : null,
    "dueDate" : null,
    "repeat" : null,
    "notifyAssignment" : true,
    "notificationSubject" : null,
    "notificationBody" : null,
    "recipients" : null,
    "subject" : null,
    "body" : null
  } ]
}