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.party.party;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.ofbiz.base.util.Debug;
024: import org.ofbiz.base.util.UtilMisc;
025: import org.ofbiz.entity.GenericDelegator;
026: import org.ofbiz.entity.GenericEntityException;
027: import org.ofbiz.entity.GenericValue;
028: import org.ofbiz.security.Security;
029: import org.ofbiz.service.DispatchContext;
030: import org.ofbiz.service.ModelService;
031: import org.ofbiz.service.ServiceUtil;
032:
033: /**
034: * Services for Party Relationship maintenance
035: */
036: public class PartyRelationshipServices {
037:
038: public static final String module = PartyRelationshipServices.class
039: .getName();
040: public static final String resource = "PartyUiLabels";
041:
042: /** Creates a PartyRelationshipType
043: *@param ctx The DispatchContext that this service is operating in
044: *@param context Map containing the input parameters
045: *@return Map with the result of the service, the output parameters
046: */
047: public static Map createPartyRelationshipType(DispatchContext ctx,
048: Map context) {
049: Map result = new HashMap();
050: GenericDelegator delegator = ctx.getDelegator();
051: Security security = ctx.getSecurity();
052: GenericValue userLogin = (GenericValue) context
053: .get("userLogin");
054:
055: String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin,
056: security, context, result, "PARTYMGR", "_CREATE");
057:
058: if (result.size() > 0)
059: return result;
060:
061: GenericValue partyRelationshipType = delegator.makeValue(
062: "PartyRelationshipType", UtilMisc.toMap(
063: "partyRelationshipTypeId", context
064: .get("partyRelationshipTypeId")));
065:
066: partyRelationshipType.set("parentTypeId", context
067: .get("parentTypeId"), false);
068: partyRelationshipType.set("hasTable", context.get("hasTable"),
069: false);
070: partyRelationshipType.set("roleTypeIdValidFrom", context
071: .get("roleTypeIdValidFrom"), false);
072: partyRelationshipType.set("roleTypeIdValidTo", context
073: .get("roleTypeIdValidTo"), false);
074: partyRelationshipType.set("description", context
075: .get("description"), false);
076: partyRelationshipType.set("partyRelationshipName", context
077: .get("partyRelationshipName"), false);
078:
079: try {
080: if (delegator.findByPrimaryKey(partyRelationshipType
081: .getPrimaryKey()) != null) {
082: return ServiceUtil
083: .returnError("Could not create party relationship type: already exists");
084: }
085: } catch (GenericEntityException e) {
086: Debug.logWarning(e, module);
087: return ServiceUtil
088: .returnError("Could not create party relationship type (read failure): "
089: + e.getMessage());
090: }
091:
092: try {
093: partyRelationshipType.create();
094: } catch (GenericEntityException e) {
095: Debug.logWarning(e.getMessage(), module);
096: return ServiceUtil
097: .returnError("Could not create party relationship type (write failure): "
098: + e.getMessage());
099: }
100:
101: result.put(ModelService.RESPONSE_MESSAGE,
102: ModelService.RESPOND_SUCCESS);
103: return result;
104: }
105: }
|