001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.humanres;
019:
020: import java.sql.Timestamp;
021: import java.util.Locale;
022: import java.util.Map;
023: import org.ofbiz.base.util.Debug;
024: import org.ofbiz.base.util.UtilMisc;
025: import org.ofbiz.base.util.UtilProperties;
026: import org.ofbiz.entity.GenericDelegator;
027: import org.ofbiz.entity.GenericEntityException;
028: import org.ofbiz.entity.GenericValue;
029: import org.ofbiz.security.Security;
030: import org.ofbiz.service.DispatchContext;
031: import org.ofbiz.service.ModelService;
032: import org.ofbiz.service.ServiceUtil;
033: import javolution.util.FastMap;
034:
035: /**
036: * Services for Human Resources
037: */
038:
039: public class HumanResServices {
040:
041: public static final String module = HumanResServices.class
042: .getName();
043: public static final String resource = "HumanResUiLabels";
044:
045: /**
046: * Create a PartyQual entity.
047: * @param ctx The DispatchContext that this service is operating in.
048: * @param context Map containing the input parameters.
049: * @return Map with the result of the service, the output parameters.
050: */
051: public static Map createPartyQual(DispatchContext ctx, Map context) {
052: Map result = FastMap.newInstance();
053: GenericDelegator delegator = ctx.getDelegator();
054: Security security = ctx.getSecurity();
055: GenericValue userLogin = (GenericValue) context
056: .get("userLogin");
057: Locale locale = (Locale) context.get("locale");
058:
059: String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin,
060: security, context, result, "PARTYMGR", "_QAL_CREATE");
061: if (result.size() > 0)
062: return result;
063:
064: String partyQualId = (String) context.get("partyQualId");
065: String partyQualTypeId = (String) context
066: .get("partyQualTypeId");
067: String institutionPartyId = (String) context
068: .get("institutionPartyId");
069: String statusId = (String) context.get("statusId");
070: String verifStatusId = (String) context.get("verifStatusId");
071: String errMsg = null;
072:
073: // partyQualId might be empty, so check it and get next seq partyQualId if empty
074: if (partyQualId == null || partyQualId.length() == 0) {
075: try {
076: partyQualId = delegator.getNextSeqId("PartyQual");
077: } catch (IllegalArgumentException e) {
078: errMsg = UtilProperties.getMessage(resource,
079: "HumanResServices.PartyQualFailureIDCreation",
080: locale);
081: return ServiceUtil.returnError(errMsg);
082: }
083: } else {
084: // if specified partyQualId starts with a number, return an error
085: if (Character.isDigit(partyQualId.charAt(0))) {
086: errMsg = UtilProperties
087: .getMessage(
088: resource,
089: "HumanResServices.PartyQualFailureIDStartsDigit",
090: locale);
091: return ServiceUtil.returnError(errMsg);
092: }
093: }
094:
095: try {
096: String title = (String) context.get("title");
097: String institutionInternalId = (String) context
098: .get("institutionInternalId");
099: String infoString = (String) context.get("infoString");
100: Timestamp fromDate = (Timestamp) context.get("fromDate");
101: Timestamp thruDate = (Timestamp) context.get("thruDate");
102: if (fromDate == null) {
103: errMsg = UtilProperties
104: .getMessage(
105: resource,
106: "HumanResServices.PartyQualFailureMissingParam",
107: locale);
108: return ServiceUtil.returnError(errMsg);
109: }
110: GenericValue partyQual = delegator.makeValue("PartyQual",
111: UtilMisc
112: .toMap(new Object[] { "partyQualId",
113: partyQualId, "partyId", partyId,
114: "partyQualTypeId", partyQualTypeId,
115: "institutionPartyId",
116: institutionPartyId, "title", title,
117: "statusId", statusId,
118: "institutionInternalId",
119: institutionInternalId,
120: "infoString", infoString,
121: "verifStatusId", verifStatusId,
122: "fromDate", fromDate, "thruDate",
123: thruDate }));
124: partyQual.setNonPKFields(context);
125: partyQual.create();
126:
127: } catch (GenericEntityException e) {
128: Debug.logWarning(e, module);
129: Map messageMap = UtilMisc.toMap("errMessage", e
130: .getMessage());
131: errMsg = UtilProperties.getMessage(resource,
132: "HumanResServices.PartyQualFailureDataSource",
133: messageMap, locale);
134: return ServiceUtil.returnError(errMsg);
135: }
136: return UtilMisc.toMap("partyQualId", partyQualId,
137: ModelService.RESPONSE_MESSAGE,
138: ModelService.RESPOND_SUCCESS);
139: }
140: }
|