KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > humanres > HumanResServices


1 /*
2  * $Id: $
3  *
4  * Copyright 2001-2006 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7  * use this file except in compliance with the License. You may obtain a copy of
8  * the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */

18
19 package org.ofbiz.humanres;
20
21 import java.sql.Timestamp JavaDoc;
22 import java.util.Locale JavaDoc;
23 import java.util.Map JavaDoc;
24 import org.ofbiz.base.util.Debug;
25 import org.ofbiz.base.util.UtilMisc;
26 import org.ofbiz.base.util.UtilProperties;
27 import org.ofbiz.entity.GenericDelegator;
28 import org.ofbiz.entity.GenericEntityException;
29 import org.ofbiz.entity.GenericValue;
30 import org.ofbiz.security.Security;
31 import org.ofbiz.service.DispatchContext;
32 import org.ofbiz.service.ModelService;
33 import org.ofbiz.service.ServiceUtil;
34 import javolution.util.FastMap;
35
36 /**
37  * Services for Human Resources
38  * @author Vinay Agarwal
39  * @version 1.0
40  */

41
42 public class HumanResServices {
43     
44     public static final String JavaDoc module = HumanResServices.class.getName();
45     public static final String JavaDoc resource = "HumanResUiLabels";
46     
47     /**
48      * Create a PartyQual entity.
49      * @param ctx The DispatchContext that this service is operating in.
50      * @param context Map containing the input parameters.
51      * @return Map with the result of the service, the output parameters.
52      */

53     public static Map JavaDoc createPartyQual(DispatchContext ctx, Map JavaDoc context) {
54         Map JavaDoc result = FastMap.newInstance();
55         GenericDelegator delegator = ctx.getDelegator();
56         Security security = ctx.getSecurity();
57         GenericValue userLogin = (GenericValue) context.get("userLogin");
58         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
59         
60         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_QAL_CREATE");
61         if (result.size() > 0)
62             return result;
63         
64         String JavaDoc partyQualId = (String JavaDoc) context.get("partyQualId");
65         String JavaDoc partyQualTypeId = (String JavaDoc) context.get("partyQualTypeId");
66         String JavaDoc institutionPartyId = (String JavaDoc) context.get("institutionPartyId");
67         String JavaDoc statusId = (String JavaDoc) context.get("statusId");
68         String JavaDoc verifStatusId = (String JavaDoc) context.get("verifStatusId");
69         String JavaDoc errMsg = null;
70         
71         // partyQualId might be empty, so check it and get next seq partyQualId if empty
72
if (partyQualId == null || partyQualId.length() == 0) {
73             try {
74                 partyQualId = delegator.getNextSeqId("PartyQual");
75             } catch (IllegalArgumentException JavaDoc e) {
76                 errMsg = UtilProperties.getMessage(resource, "HumanResServices.PartyQualFailureIDCreation", locale);
77                 return ServiceUtil.returnError(errMsg);
78             }
79         } else {
80             // if specified partyQualId starts with a number, return an error
81
if (Character.isDigit(partyQualId.charAt(0))) {
82                 errMsg = UtilProperties.getMessage(resource, "HumanResServices.PartyQualFailureIDStartsDigit", locale);
83                 return ServiceUtil.returnError(errMsg);
84             }
85         }
86         
87         try {
88             String JavaDoc title = (String JavaDoc) context.get("title");
89             String JavaDoc institutionInternalId = (String JavaDoc) context.get("institutionInternalId");
90             String JavaDoc infoString = (String JavaDoc) context.get("infoString");
91             Timestamp JavaDoc fromDate = (Timestamp JavaDoc) context.get("fromDate");
92             Timestamp JavaDoc thruDate = (Timestamp JavaDoc) context.get("thruDate");
93             if (fromDate == null) {
94                 errMsg = UtilProperties.getMessage(resource,"HumanResServices.PartyQualFailureMissingParam", locale);
95                 return ServiceUtil.returnError(errMsg);
96             }
97             GenericValue partyQual = delegator.makeValue("PartyQual", UtilMisc.toMap(new Object JavaDoc[] {
98                 "partyQualId", partyQualId,
99                 "partyId", partyId,
100                 "partyQualTypeId", partyQualTypeId,
101                 "institutionPartyId", institutionPartyId,
102                 "title", title,
103                 "statusId", statusId,
104                 "institutionInternalId", institutionInternalId,
105                 "infoString", infoString,
106                 "verifStatusId", verifStatusId,
107                 "fromDate", fromDate,
108                 "thruDate", thruDate
109             }));
110             partyQual.setNonPKFields(context);
111             partyQual.create();
112             
113         } catch (GenericEntityException e) {
114             Debug.logWarning(e, module);
115             Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
116             errMsg = UtilProperties.getMessage(resource, "HumanResServices.PartyQualFailureDataSource", messageMap, locale);
117             return ServiceUtil.returnError(errMsg);
118         }
119         return UtilMisc.toMap(
120                 "partyQualId", partyQualId,
121                 ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
122     }
123 }
124
Popular Tags