[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6ACP73RA26RW2Q2BMYT15NN":3,"skill-same:01M6ACP73RA26RW2Q2BMYT15NN":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":17,"categories":18,"keywords":29,"publishedAt":32,"linkOnly":33,"markdownContent":34,"markdownBody":34,"frontMatter":35,"refName":36,"commitSha":37,"skillDirectory":38,"forksCount":39,"repositoryHtmlUrl":40,"repositoryHomepageUrl":41,"ownerHtmlUrl":42,"ownerBlogUrl":43,"ownerDescription":7,"updatedAt":44,"install":45,"resources":58},"01M6ACP73RA26RW2Q2BMYT15NN","manage-java","Java 开发管理",null,"","apache\u002Fofbiz-plugins","apache","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F47359?v=4","01M6AC83E6K4FDKK7HZ8WNMQKE","The Apache Software Foundation","01M6ACMJJ1Q4WYATY4GXZ2FAVD",178,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-java\u002FSKILL.md",[19,24],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQ6TQZN6R52WBJ9H8NRMQM","软件开发工程师","PROFESSION","适用职业",{"categoryNo":25,"categoryName":26,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BT7QVANT4709358VEJK53E","代码实现","SCENARIO","使用场景",[30,31],"java","manage java","2026-11-10 10:12:30",false,"\u003C!--\nLicensed to the Apache Software Foundation (ASF) under one\nor more contributor license agreements.  See the NOTICE file\ndistributed with this work for additional information\nregarding copyright ownership.  The ASF licenses this file\nto you under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance\nwith the License.  You may obtain a copy of the License at\n\nhttp:\u002F\u002Fwww.apache.org\u002Flicenses\u002FLICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an\n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied.  See the License for the\nspecific language governing permissions and limitations\nunder the License.\n-->\n\n---\nname: manage-java\ndescription: |-\n  - Implementing OFBiz services (business logic) in Java.\n  - Handling transactions and service contracts.\n  - Requires manage-java-patterns for shared standards.\n---\n\n# Skill: manage-java\n## Goal\nImplement robust, transaction-aware business logic in Java for OFBiz services. This is recommended for core domain logic, performance-critical integrations, or where strict typing and deep 3rd-party library integration are required.\n\n## Triggers\n**ALWAYS** read this skill when:\n- Creating or modifying Java services in an OFBiz component.\n- Implementing business logic that requires transaction management.\n- Debugging service execution or runtime reflection errors.\n\n> [!TIP]\n> **See [manage-java-patterns](..\u002Fmanage-java-patterns\u002FSKILL.md)** for shared Java standards (logging constants, localization utilities, and basic exception handling).\n\n\n## Rules & Procedures\n### 1. Class Structure & Worker Patterns\n- Create service classes under the component’s Java source directory so they’re on the OFBiz runtime classpath (FQCN must match `services.xml` location).\n- Keep worker methods stateless and side-effect controlled. This ensures testability and safe reuse across services, events, and screens.\n- Pass dependencies like `Delegator`, `LocalDispatcher`, `GenericValue userLogin`, `Locale`, and `TimeZone` explicitly to worker methods to ensure thread-safety and avoid implicit dependencies.\n\n### 2. Standard Method Signature\n- A Java service must be a `public static` method.\n- It receives a `DispatchContext` and a `Map\u003CString, ? extends Object>` of input parameters.\n- It returns a `Map\u003CString, Object>` containing the output parameters.\n```java\npublic static Map\u003CString, Object> myService(DispatchContext dctx, Map\u003CString, ? extends Object> context)\n```\n\n### 3. Core Tools and Parameters\n- **Delegator\u002FDispatcher**: Always retrieve these from the `DispatchContext`.\n  ```java\n  Delegator delegator = dctx.getDelegator();\n  LocalDispatcher dispatcher = dctx.getDispatcher();\n  GenericValue userLogin = (GenericValue) context.get(\"userLogin\");\n  ```\n- **Data Access**: Use `dctx.getDelegator()` to perform entity lookups.\n- **Service Parameters**: Inputs are received via the `context` Map.\n  - **Rule**: Consult **[manage-java-patterns](..\u002Fmanage-java-patterns\u002FSKILL.md)** for `EntityQuery` performance, `UtilValidate`, normalization, and batch-write patterns.\n\n### 4. Locale and Timezone Awareness in Services\n- Always pass context-provided `Locale` and `TimeZone` objects to sub-services and worker methods.\n- **Rule**: Follow the \"Date & Timestamp Handling\" and \"Localization\" patterns in **[manage-java-patterns](..\u002Fmanage-java-patterns\u002FSKILL.md)**. Never interpret user-entered local date\u002Ftime without an explicit `timeZone`.\n\n### 5. Exposing Service in XML\n- The service must be explicitly registered in `services.xml` specifying `engine=\"java\"`.\n```xml\n\u003Cservice name=\"myService\" engine=\"java\" location=\"com.example.ofbiz.MyJavaServices\" invoke=\"myService\" auth=\"true\">\n    \u003Cattribute name=\"myInputParam\" type=\"String\" mode=\"IN\"\u002F>\n\u003C\u002Fservice>\n```\n\n## Guardrails\n- **Service Registration Match**: Ensure the Java method name and parameters match exactly what is defined in the `\u003Cservice>` definition in `services.xml`.\n- **Service Return Values**: **ALWAYS** use `ServiceUtil.returnSuccess()`, `ServiceUtil.returnError()`, or `ServiceUtil.returnFailure()` to ensure the dispatcher natively understands the transaction outcome.\n- **Child Service Verification**: When invoking sub-services, immediately check if they failed and safely bubble the error using `ServiceUtil.isError()`.\n  - **Rule**: Follow the \"Service Invocation & Context\" pattern in **[manage-java-patterns](..\u002Fmanage-java-patterns\u002FSKILL.md)** to ensure consistent error handling and context propagation.\n- **Resource Management (ELI)**: If using `EntityListIterator`, you **MUST** ensure it is safely closed. Refer to the \"Batch Writes & Chunking\" section in **[manage-java-patterns](..\u002Fmanage-java-patterns\u002FSKILL.md)** for the `try-with-resources` pattern.\n- **Authentication\u002FuserLogin**: If service is `auth=\"true\"`, treat missing or invalid `userLogin` as a user error; don't wait for a NullPointerException (NPE) to crash the system. Validate `userLogin` exists when required and return a clean error if missing.\n\n## Bad Practices & Anti-patterns\n\n### Anti-pattern: Static State Mutation (Race Conditions)\n**Pitfall**: Using non-final static variables to store state or temporary data. Since OFBiz services are executed concurrently by the service engine, this leads to unpredictable race conditions and memory leaks.\n- **❌ Bad (Shared Static State)**:\n  ```java\n  private static Map\u003CString, Object> tempCache = new HashMap\u003C>(); \u002F\u002F Global state!\n  public static Map\u003CString, Object> myService(DispatchContext dctx, Map\u003CString, ?> context) {\n      tempCache.put(\"userId\", context.get(\"userId\")); \u002F\u002F Overwritten by other threads\n      ...\n  }\n  ```\n- **✅ Good (Thread-Safe Context)**: \n  ```java\n  public static Map\u003CString, Object> myService(DispatchContext dctx, Map\u003CString, ?> context) {\n      \u002F\u002F Keep state local to the method\u002Fstack\n      String userId = (String) context.get(\"userId\");\n      ...\n  }\n  ```\n\n### Anti-pattern: Manual Transaction Overkill\n**Pitfall**: Manually starting and committing JDBC transactions inside a service. This is error-prone and interferes with the service engine's automatic transaction handling.\n- **❌ Bad (Manual JDBC\u002FTransactionUtil)**:\n  ```java\n  TransactionUtil.begin();\n  try {\n      \u002F\u002F logic\n      TransactionUtil.commit();\n  } catch (Exception e) {\n      TransactionUtil.rollback();\n  }\n  ```\n- **✅ Good (Declarative Transactions)**: \n  ```xml\n  \u003C!-- Set requirement in services.xml -->\n  \u003Cservice name=\"myService\" engine=\"java\" require-new-transaction=\"true\" ... \u002F>\n  ```\n\n### Anti-pattern: Result Map Pollution\n**Pitfall**: Returning parameters in the result map that are NOT defined in the `services.xml` contract. This makes the service hard to test, debug, and maintain.\n- **❌ Bad**:\n  ```java\n  Map\u003CString, Object> result = ServiceUtil.returnSuccess();\n  result.put(\"undeclaredFlag\", true); \u002F\u002F Not in XML, confusing for callers\n  return result;\n  ```\n- **✅ Good**: \n  ```java\n  \u002F\u002F Only return what is defined in \u003Cattribute mode=\"OUT\" \u002F>\n  Map\u003CString, Object> result = ServiceUtil.returnSuccess();\n  result.put(\"orderId\", orderId); \n  return result;\n  ```\n\n### Anti-pattern: Silent Failure (Swallowing Exceptions)\n**Pitfall**: Catching exceptions and returning a success message without actually handling or reporting the failure.\n- **❌ Bad**:\n  ```java\n  try {\n      processOrder();\n  } catch (Exception e) {\n      \u002F\u002F Swallowed! Caller thinks it worked.\n  }\n  return ServiceUtil.returnSuccess();\n  ```\n- **✅ Good**: \n  ```java\n  try {\n      processOrder();\n  } catch (Exception e) {\n      Debug.logError(e, MODULE);\n      return ServiceUtil.returnError(\"Processing Failed: \" + e.getMessage());\n  }\n  ```\n\n### Anti-pattern: Direct JDBC Queries\n**Pitfall**: Bypassing the `Delegator` for raw JDBC (`java.sql.Connection`). This breaks caching, service triggers (ECAs), database independence, and standard OFBiz transaction synchronization.\n- **❌ Bad (Raw SQL)**:\n  ```java\n  \u002F\u002F Bypasses framework; breaks caching and portability\n  Connection conn = DriverManager.getConnection(url); \n  Statement stmt = conn.createStatement();\n  stmt.executeUpdate(\"UPDATE PRODUCT SET PRODUCT_NAME='...' WHERE PRODUCT_ID='...' \");\n  ```\n- **✅ Good (Use Delegator)**: \n  ```java\n  \u002F\u002F Maintains caching, security, and transaction integrity\n  GenericValue product = EntityQuery.use(delegator).from(\"Product\")\n          .where(\"productId\", id).queryOne();\n  product.set(\"productName\", name);\n  product.store();\n  ```\n\n### Other Bad Practices\n- **Java for simple CRUD**: Use the `entity-auto` engine instead for simple create\u002Fupdate operations.\n- **Hardcoding UI Strings**: Returning inline string literals prevents internationalization. Use `UtilProperties.getMessage`.\n- **Assuming Optional Parameter Types**: Never assume `context.get(\"param\")` exists without an `isEmpty()` validation just because it is `optional=\"true\"`.\n- **Mixing Loop-of-Death**: Refer to **[manage-java-patterns](..\u002Fmanage-java-patterns\u002FSKILL.md)** for batching and background job deferral.\n\n## Common Code Patterns (Examples)\n**Example: Advanced Java Service Implementation**\n```java\npublic static Map\u003CString, Object> updateExampleStatus(DispatchContext dctx, Map\u003CString, ? extends Object> context) {\n    Delegator delegator = dctx.getDelegator();\n    LocalDispatcher dispatcher = dctx.getDispatcher();\n    String exampleId = (String) context.get(\"exampleId\");\n    String statusId = (String) context.get(\"statusId\");\n    Locale locale = (Locale) context.get(\"locale\");\n    Map\u003CString, Object> result = ServiceUtil.returnSuccess();\n    \n    \u002F\u002F Explicit Validation instead of just relying on exceptions\n    if (UtilValidate.isEmpty(exampleId)) {\n        return ServiceUtil.returnError(UtilProperties.getMessage(\"MyUiLabels\", \"ExampleIdMissing\", locale));\n    }\n    \n    try {\n        GenericValue example = EntityQuery.use(delegator).from(\"Example\")\n                .where(\"exampleId\", exampleId).queryOne();\n        if (example == null) {\n            return ServiceUtil.returnError(UtilProperties.getMessage(\"MyUiLabels\", \"NotFound\", locale));\n        }\n        \n        example.set(\"statusId\", statusId);\n        example.store();\n        \n        \u002F\u002F Hypothetical explicit sub-service invocation verification\n        Map\u003CString, Object> subCtx = UtilMisc.toMap(\n            \"userLogin\", context.get(\"userLogin\"),\n            \"locale\", locale,\n            \"timeZone\", context.get(\"timeZone\"),\n            \"exampleId\", exampleId,\n            \"statusId\", statusId\n        );\n        Map\u003CString, Object> notifyResult = dispatcher.runSync(\"notifyStatusChange\", subCtx);\n        if (ServiceUtil.isError(notifyResult)) {\n            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(notifyResult));\n        }\n        \n    } catch (GenericEntityException | GenericServiceException e) {\n        Debug.logError(e, \"Error updating status for Example: \" + exampleId, MODULE);\n        String errMsg = UtilProperties.getMessage(\"CommonUiLabels\", \"CommonSystemError\", locale);\n        return ServiceUtil.returnError(errMsg);\n    }\n    \n    return result;\n}\n```\n",{},"trunk","6c6c27710443de03e9247605d33a2e2f5bc3d1e2","ai-agent-skills\u002Fmanage-java",222,"https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins","https:\u002F\u002Fofbiz.apache.org\u002F","https:\u002F\u002Fgithub.com\u002Fapache","https:\u002F\u002Fwww.apache.org\u002F","2026-11-12 22:04:06",{"source":9,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add apache\u002Fofbiz-plugins --skill manage-java",{"tool":51,"command":52},"bunx","bunx skills add apache\u002Fofbiz-plugins --skill manage-java",{"tool":54,"command":55},"pnpm","pnpm dlx skills add apache\u002Fofbiz-plugins --skill manage-java","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-java\u002FSKILL.md",true,[],[60,72,84,98,112,126],{"skillNo":61,"name":62,"nameZh":63,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":64,"categories":65,"keywords":70,"publishedAt":32},"01M6ACQSN90YKJZ92MQ52D9R8H","prepush-readiness","推送前就绪检查","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fprepush-readiness\u002FSKILL.md",[66,67],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":68,"categoryName":69,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BR5V701HCN066VEP7H4812","代码仓库协作管理",[71],"prepush readiness",{"skillNo":73,"name":74,"nameZh":75,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":76,"categories":77,"keywords":82,"publishedAt":32},"01M6ACQPR1WRA751V4DXVC3AHF","manage-webapps","Web 应用管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-webapps\u002FSKILL.md",[78,79],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":80,"categoryName":81,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BWKS60NTYJHFE9FQSXGDKS","低代码应用开发",[83],"manage webapps",{"skillNo":85,"name":86,"nameZh":87,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":88,"categories":89,"keywords":96,"publishedAt":32},"01M6ACQMCX8Z7NY2CE08NCV6ND","manage-themes","主题管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-themes\u002FSKILL.md",[90,93],{"categoryNo":91,"categoryName":92,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQ6TQMKHSMFVQHR2KYAEVN","界面设计师",{"categoryNo":94,"categoryName":95,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BRASNPVNJVQQJ4KZX8XM5D","前端开发与界面实现",[97],"manage themes",{"skillNo":99,"name":100,"nameZh":101,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":102,"categories":103,"keywords":110,"publishedAt":32},"01M6ACQHYN20AFWF6TKK4RGQ8A","manage-tests","测试管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-tests\u002FSKILL.md",[104,107],{"categoryNo":105,"categoryName":106,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQGD5WG86P4AQ5GPSSKBFR","测试工程师",{"categoryNo":108,"categoryName":109,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BQJH394GT47X57A9Q8G7HX","测试与质量保障",[111],"manage tests",{"skillNo":113,"name":114,"nameZh":115,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":116,"categories":117,"keywords":124,"publishedAt":32},"01M6ACQFRMW7R45YD3HRAXPGWF","manage-templates","模板管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-templates\u002FSKILL.md",[118,121],{"categoryNo":119,"categoryName":120,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BQ6TK1MPB82068236GSXDE","文档处理",{"categoryNo":122,"categoryName":123,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQ6TPH3VQWKQZXV7EPF8VZ","办公行政人员",[125],"manage templates",{"skillNo":127,"name":128,"nameZh":129,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":130,"categories":131,"keywords":138,"publishedAt":32},"01M6ACQCSSDZQMD8VX2K3WRR93","manage-strategies","策略管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-strategies\u002FSKILL.md",[132,135],{"categoryNo":133,"categoryName":134,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BTXF8K9DFQC4T4TXVH0NMZ","策略与托管设置管理",{"categoryNo":136,"categoryName":137,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8C6RQ852C9AEJFCBGG1YA7S","IT 管理员",[139],"manage strategies"]