使用 HCM 数据加载程序集成 Web 服务

您可以使用 HCM 数据加载程序 SOAP Web 服务导入和加载 WebCenter 内容服务器上存放的数据文件。您可以从 Oracle Cloud HCM 用户界面中的导入和加载数据页面手动处理这些数据文件。

您必须首先安装 Oracle JDeveloper 11.1.1.9,以获取从 Oracle Cloud HCM 调用 SOAP Web 服务所需的库。

关于 HCM 数据加载程序集成服务

可以使用 Oracle Cloud HCM SOAP Web 服务使用 SOAP API 上载文件。

您可以从 Developer Connect 链接中的 Oracle Fusion Cloud Human Resources 获取数据加载程序服务 Web 服务详细信息,该链接位于导航器菜单中的工具下,就像任何其他 SOAP Web 服务一样。

WebCenter Content 服务器上放置包含 DAT 文件的 ZIP 文件后,可以调用 SOAP Web 服务。然后,您可以使用 hcm/dataloader/import 帐户保护该帐户。此 Web 服务可用于在 Oracle Cloud HCM 中导入和加载数据。

关于调用 HCM 数据加载程序的 SOAP 信封

调用 HCM 数据加载程序 SOAP Web 服务时,会发送和接收请求和响应信封。
可以使用这些信封向 HCMDataLoader SOAP Web 服务发出请求:
http://{Host}/hcmCommonDataLoader/HCMDataLoader

关于 importAndLoadData 方法

importAndLoadData 方法启动处理 WebCenter Content 服务器上托管的数据文件。它是只返回已提交进程的 ProcessId 的异步作业。

使用此信封调用 SOAP Web 服务中的 importAndLoadData 函数。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:importAndLoadData xmlns:ns1="http://xmlns.oracle.com/apps/hcm/common/dataLoader/core/dataLoaderIntegrationService/types/">
            <ns1:ContentId></ns1:ContentId>
            <ns1:Parameters></ns1:Parameters>
        </ns1:importAndLoadData>
    </soap:Envelope>

与信封一起发送的 importAndLoadData 方法的参数为:

ContentIdWebCenter Content 服务器上文件的内容 ID(与 WebCenter Content Java 调用中的 dDocName 参数相同的值)。

参数:名称/值对。以下参数名称可用,但不是必需的:

  • ImportMaximumErrors:业务对象在导入流程结束前发生的文件行出错的百分比。

  • LoadMaximumErrors:业务对象实例在验证和加载流程结束前对业务对象实例可能发生的错误百分比。

  • LoadConcurrentThreads: 验证或加载时并发线程的数量。

  • LoadGroupSize:并发线程处理为单个工作单位的业务对象数。

  • FileEncryption:文件加密的类型。例如,基于密码的加密 (Password Based Encryption, PBE)。

  • DeleteSourceFileYN 值。如果设置为 Y 或留空,则在将文件内容传输到 HCM 数据加载程序阶段表后,从 WebCenter Content 服务器中删除源文件,并且不再需要该文件。

例如,<ns1:Parameters> 标记可以包含以下名称和值对:<ns1:Parameters>ImportMaximumErrors=100,LoadMaximumErrors=100,LoadConcurrentThreads=4,FileEncryption=PGPSIGNED,DeleteSourceFile=N</ns1:Parameters>

服务器使用以下信封进行响应:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"> 
	<env:Header> <wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To> 
	  <wsa:Action>http://xmlns.oracle.com/apps/hcm/common/dataLoader/core/dataLoaderIntegrationService/HCMDataLoader/importAndLoadDataResponse</wsa:Action>
	   <wsa:MessageID>urn:uuid:ab36195f-775b-4688-a0e4-8a4e531e904c</wsa:MessageID>
	   <wsa:RelatesTo>urn:uuid:74c7b631-c20a-4d49-bf36-1f483f3dc43e</wsa:RelatesTo>
   </env:Header> 
	<env:Body> <ns0:importAndLoadDataResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/common/dataLoader/core/dataLoaderIntegrationService/types/"> <result xmlns="http://xmlns.oracle.com/apps/hcm/common/dataLoader/core/dataLoaderIntegrationService/types/">7958</result> </ns0:importAndLoadDataResponse> 
	</env:Body> 
</env:Envelope>

关于 getDataSetStatus 方法

getDataSetStatus 方法返回指定数据文件的当前状态。

使用此信封调用 SOAP Web 服务中的 getDataSetStatus 函数。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:getDataSetStatus xmlns:ns1="http://xmlns.oracle.com/apps/hcm/common/dataLoader/core/dataLoaderIntegrationService/types/">
             <ns1:Parameters></ns1:Parameters>
        </ns1:getDataSetStatus>
    </soap:Envelope>

与信封一起发送的 getDataSetStatus 方法的参数为:

ContentIdWebCenter Content 服务器上文件的内容 ID(与 WebCenter Content Java 调用中的 dDocName 参数相同的值)。

ProcessId :由 importAndLoadData 方法启动和返回的进程的 ID。

生成用于调用 HCM DataLoader 的代理类

调用 Oracle Cloud HCM SOAP Web 服务的一个选项是使用生成的代理类。

您可以通过向所选生成器提供服务 WSDL 文件的 URL 来生成代理类。这些代理类用于调用 Web 服务。

注:

Oracle Cloud HCM SOAP Web 服务受 Oracle Web Services Manager (OWSM) 安全策略保护。
  1. 登录 Oracle Cloud HCM
  2. 导航器 菜单中,找到“工具”标题,然后单击 开发人员连接
  3. 查找 搜索框中,键入 数据加载程序 ,然后单击搜索图标。
  4. 单击 数据加载器 服务。此时将显示服务的 汇总 页。
    “概要”页显示与 SOAP Web 服务相关的信息,例如 WSDL 文件位置。
  5. 打开命令提示符,然后运行 wsimport 命令,该命令位于 $JAVA_HOME/bin
    wsimport -s <Provide the folder where the generated files need to be placed> -d <Provide the folder where the generated files need to be placed> <The HCM Data Loader Integration Service URL>

    在命令中,第一个参数是需要放置生成文件的文件夹。第二个参数也是需要放置生成文件的文件夹。第三个参数是 HCM 数据加载程序 WSDL URL。例如:

    wsimport -s "D:\HCMDataLoader" -d "D:\ HCMDataLoader" https://{host}/hcmCommonDataLoader/HCMDataLoader?wsdl

    生成的文件将放置在以下两个文件夹中:

    • com

    • sdo

  6. 将生成的代码添加到 JAR 文件:
    zip loaderIntegrationProxy.jar -r * -

关于使用 HCM 数据加载程序时的安全性影响

当客户机调用 HCM 数据加载程序 SOAP Web 服务时,后者必须满足消息保护策略,以确保以加密方式或通过 SSL 传输层传输有效负载。

使用以下 Oracle Web Services Manager 策略保护 HCMDataLoader Web 服务:oracle/wss11_saml_or_username_token_with_message_protection_service_policy

在客户端,您可以使用以下 Oracle Web Services Manager 策略:oracle/wss11_username_token_with_message_protection_client_policy

要使用此策略,必须使用服务器提供的公共密钥加密消息。当消息到达服务器时,可以通过服务器的私钥解密消息。您可以创建一个 KeyStore 来导入服务 WSDL 文件中提供的证书,但出于安全原因,您应在每次运行代码时提示用户输入 Oracle Cloud HCM 密码。

您可以创建一个属性文本文件,该文件可以在代码内进行解析以访问 Keystore 信息,例如:

FUSION_USERNAME=<Your Oracle Global Human Resources Cloud User Name>
DATAPATH=C:\\My\\Assets\\cloud.asset.hcm.java-dataload-example\\data\\
HCM_DATA_LOADER_SERVICE_WSDL_LOCATION=https://<<FusionURL>/hcmCommonDataLoader/HCMDataLoader?wsdl
UCM_IDC_WEBSERVICE_LOCATION=https://<FusionURL>/idcws/GenericSoapPort
KEYSTORE_LOCATION=<Your Keystore trust location>
KEYSTORE_PASSWORD=<YourTrustPassword>
KEYSTORE_ALIAS=orakey
GETDATASETSTATUS_DELAY=5
OK=OK
ERROR=Error
WARNING=Warning
CSV_FILE_ENCODING=UTF-8
DATA_SEPERATOR=;

使用以下项提示用户提供其 Oracle Cloud HCM 身份证明:

// Accept password from user
Scanner scanReader = new Scanner(System.in);  // Reading from System.in
System.out.println("Enter password for user "+propertiesFile.getProperty("FUSION_USERNAME")+" :");
fusionUserPass= scanReader.next(); // Scans the next token of the input as an int.
scanReader.close();

在本示例中,fusionUserPass 是一个变量,可用于存储用户的 Oracle Cloud HCM 密码,然后传递给 HCM 数据加载程序 SOAP Web 服务。

调用 HCM DataLoader SOAP Web 服务

您可以使用 Java 类中的 HCM 数据加载程序 SOAP Web 服务将数据从 ZIP 文件加载到 Oracle Cloud HCM

首先创建 ZIP 文件,然后以手动或编程方式将其上载到 WebCenter Content 服务器。然后,可以使用 importAndLoadData Web 服务加载数据。

注:

此解决方案中提供的代码示例已通过 JDK 版本 8 进行测试,以在 Oracle WebLogic Server 12c 上调用 Web 服务。要与其他 JDK 和 Oracle WebLogic Server 版本一起使用,请使用特定于所需版本的库测试代码。

  1. 在文件夹中创建客户机类:/com/oracle/xmlns/apps/hcm/common/dataloader/core/dataloaderintegrationservice/
    要生成类,您需要具有以下 JAR 文件:
    • 对于 WebLogic 服务器 11g:ws.api_1.1.0.0.jar
    • 对于 WebLogic Server 12c:wls-api.jar

    此 JAR 文件位于 JDeveloper 安装文件夹中的以下位置:

    • 对于 WebLogic 服务器 11g:$MIDDLEWARE_HOME/modules
    • 对于 WebLogic Server 12c:$MIDDLEWARE_HOME/wlserver/server/lib
  2. 确保在 Java 代码中导入以下 Java 库:
    import com.oracle.xmlns.apps.hcm.common.dataloader.core.dataloaderintegrationservice.HCMDataLoader;
    import com.oracle.xmlns.apps.hcm.common.dataloader.core.dataloaderintegrationservice.HCMDataLoader_Service;
    import com.oracle.xmlns.apps.hcm.common.dataloader.core.dataloaderintegrationservice.ServiceException;
    import javax.xml.ws.BindingProvider;
    import weblogic.wsee.jws.jaxws.owsm.SecurityPolicyFeature;
    
  3. 创建一个返回 HCMDataLoader 对象的函数,并接收 urlusernamepasswordkeystore 作为参数。例如:
    public static HCMDataLoader getHCMDataLoaderService(String url, String username, String password, String keystore)
    			throws MalformedURLException {
    		//The code in the next steps is placed within the function body
    }
  4. 在函数主体内,创建 SOAP Web 服务对象。
    HCMDataLoader_Service webService = new HCMDataLoader_Service(new URL("/hcmCommonDataLoader/HCMDataLoader?wsdl));
    
    SecurityPolicyFeature[] securityFeatures = new SecurityPolicyFeature[] { 
    				new SecurityPolicyFeature("oracle/wss_username_token_over_ssl_client_policy") 
    }; 
    
    HCMDataLoader hcmDataLoader = webService.getHCMDataLoaderSoapHttpPort(securityFeatures);
    
  5. 创建 BindingProvider 对象并设置其上下文参数。
    BindingProvider wsbp = (BindingProvider) hcmDataLoader;
    Map<String, Object> requestContext = wsbp.getRequestContext();
    requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
    return hcmDataLoader;
  6. 使用 importAndLoadData 函数将数据加载到 Oracle Cloud HCM 中。
    HCMDataLoader hcmDataLoaderService = HCMDataLoaderUtil.getHCMDataLoaderService(url, username, password,
    		keystore);
    
    String parameters = ""; // args[1];
    
    try {
    	String response = hcmDataLoaderService.importAndLoadData(contentId, parameters);
    
    	return response;
    } catch (ServiceException e) {
    	logger.severe("Error occurred during importAndLoad call  ..." + e.getLocalizedMessage());
    	throw e;
    }
  7. 可以创建另一个函数来从上载的数据文件中获取状态:
    public static String invokeGetDataSetStatus(String url, String username, String password, String keystore,
    			Long processId, String getDataSetStatusDelay)
    			throws ServiceException, ParserConfigurationException, SAXException, IOException, InterruptedException {
    				//The code in the next steps is placed within this function body
    }
  8. 使用 getDataSetStatus 函数检索状态响应:
    HCMDataLoader hcmLoaderService = getHCMDataLoaderService(url, username, password, keystore);
    String response = hcmLoaderService.getDataSetStatus("ProcessId=" + processId);
    String loadStatus = getLoadStatusFromResponse(response); // To save the status from the response to a String variable

    getDataSetStatus 返回 XML 对象,其中包含有关加载和导入过程的详细信息。

  9. 创建另一个函数来解析 getDataSetStatus 调用中的 XML 响应。
    public static String getLoadStatusFromResponse(String xmlResult)
    			throws ParserConfigurationException, SAXException, IOException {
    		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    		DocumentBuilder builder = factory.newDocumentBuilder();
    		Document document = builder.parse(new InputSource(new StringReader(xmlResult)));
    		NodeList flowList = document.getElementsByTagName("DATA_SET_STATUS");
    		NodeList childList;
    		for (int i = 0; i < flowList.getLength(); i++) {
    			childList = flowList.item(i).getChildNodes();
    			for (int j = 0; j < childList.getLength(); j++) {
    				Node childNode = childList.item(j);
    				if ("DATA_SET".equals(childNode.getNodeName())) {
    					NodeList dataSeteChildNodes = childNode.getChildNodes();
    					{
    						for (int k = 0; k < dataSeteChildNodes.getLength(); k++) {
    							{
    								Node childDSNode = dataSeteChildNodes.item(k);
    								if ("STATUS".equals(childDSNode.getNodeName())) {
    									String status = dataSeteChildNodes.item(k).getTextContent().trim();
    									System.out.println("Current Status of the Data Set "
    											+ dataSeteChildNodes.item(k).getTextContent().trim());
    									return status;
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    		return "ERROR";
    	}
    
  10. 完成 Java 代码后,使用 javac 命令对其进行编译:
    • 对于 WebLogic 服务器 11g:
      javac -classpath path of the folder where with generated JAX-WS files;location of ws.api_1.1.0.0.jar HCMDataLoaderServiceSoapHttpPortClient.java
    • 对于 WebLogic 服务器 12c:
      javac -classpath path of the folder where with generated JAX-WS files;location of wls-api.jar HCMDataLoaderServiceSoapHttpPortClient.java
  11. 运行 HCMDataLoaderServiceSoapHttpPortClient 类以使用 java 命令调用 HCM 数据加载程序集成服务:
    • 对于 WebLogic 服务器 11g:
      java -classpath path of the folder where with generated JAX-WS files;location of weblogic.jar;location of jrf.jar com.oracle.xmlns.apps.hcm.common.dataloader.core.dataloaderintegrationservice.HCMDataLoaderServiceSoapHttpPortClient ContentId Parameters
    • 对于 WebLogic 服务器 12c:
      java -classpath path of the folder where with generated JAX-WS files;location of wlthint3client.jar;location of wls-api.jar com.oracle.xmlns.apps.hcm.common.dataloader.core.dataloaderintegrationservice.HCMDataLoaderServiceSoapHttpPortClient ContentId Parameters