reusing service createPartyRelationship

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

reusing service createPartyRelationship

RolandH-2
Hi all,

now I'm trying to add an relationship between two parties, using
createPartyRelationship from applications/party/servicedef/services.xml,
the description tells:
>   if partyIdFrom is not specified the partyId of the current userLogin
> will be used;
so, I'm trying:

Map createPartyRelationshipMap =
        UtilMisc.toMap(
               "roleTypeIdTo", "CUSTOMER",
               "userLogin", context.get("userLogin")
               );
[...]
createPartyRelationshipMap.put("partyIdTo",
createPersonResult.get("partyId"));
Map createPartyRelationshipResult =
dispatcher.runSync("createPartyRelationship", createPartyRelationshipMap);
if (ServiceUtil.isError(createPartyRelationshipResult)) {
 throw new
GenericServiceException(ServiceUtil.getErrorMessage(createPartyRelationshipResult));
}

and I'm getting:

> Failure in create operation for entity [PartyRelationship]:
> org.ofbiz.entity.GenericEntityException: Error while inserting:
> [GenericEntity:PartyRelationship][createdStamp,2008-06-06
> 16:18:44.82(java.sql.Timestamp)][createdTxStamp,2008-06-06
> 16:18:42.419(java.sql.Timestamp)][fromDate,2008-06-06
> 16:18:44.811(java.sql.Timestamp)][lastUpdatedStamp,2008-06-06
> 16:18:44.82(java.sql.Timestamp)][lastUpdatedTxStamp,2008-06-06
> 16:18:42.419(java.sql.Timestamp)][partyIdTo,10210(java.lang.String)][roleTypeIdFrom,_NA_(java.lang.String)][roleTypeIdTo,CUSTOMER(java.lang.String)]
> (SQL Exception while executing the following:INSERT INTO
> public.PARTY_RELATIONSHIP (PARTY_ID_FROM, PARTY_ID_TO,
> ROLE_TYPE_ID_FROM, ROLE_TYPE_ID_TO, FROM_DATE, THRU_DATE, STATUS_ID,
> RELATIONSHIP_NAME, SECURITY_GROUP_ID, PRIORITY_TYPE_ID,
> PARTY_RELATIONSHIP_TYPE_ID, PERMISSIONS_ENUM_ID, POSITION_TITLE,
> COMMENTS, LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP,
> CREATED_TX_STAMP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?)(ERROR: null value in column "party_id_from" violates not-null
> constraint)). Rolling back transaction.
is the description wrong, or my understanding of the description?

Greetings,
Roland
Reply | Threaded
Open this post in threaded view
|

Re: reusing service createPartyRelationship

Ashish Vijaywargiya
You can take a help of the following URL to get more insight about the code
:-

https://localhost:8443/partymgr/control/EditPartyRelationships?partyId=admin

Inside EditPartyRelationships.ftl file line # 103 partyIdFrom is passed as
the hidden parameter to the service and the "partyId" has been set in the
Screen definition.
<input type="hidden" name="partyIdFrom" value="${partyId}"/>

You may need to pass the partyIdFrom in your service map as its passed as
the hidden field in the PartyRelationship screen that is present in Ofbiz.
Please let us know if you are unable to find the way from my comments.

--
Ashish




On Fri, Jun 6, 2008 at 10:25 AM, RolandH <[hidden email]> wrote:

> Hi all,
>
> now I'm trying to add an relationship between two parties, using
> createPartyRelationship from applications/party/servicedef/services.xml, the
> description tells:
>
>>  if partyIdFrom is not specified the partyId of the current userLogin will
>> be used;
>>
> so, I'm trying:
>
> Map createPartyRelationshipMap =
>       UtilMisc.toMap(
>              "roleTypeIdTo", "CUSTOMER",
>              "userLogin", context.get("userLogin")
>              );
> [...]
> createPartyRelationshipMap.put("partyIdTo",
> createPersonResult.get("partyId"));
> Map createPartyRelationshipResult =
> dispatcher.runSync("createPartyRelationship", createPartyRelationshipMap);
> if (ServiceUtil.isError(createPartyRelationshipResult)) {
> throw new
> GenericServiceException(ServiceUtil.getErrorMessage(createPartyRelationshipResult));
> }
>
> and I'm getting:
>
>> Failure in create operation for entity [PartyRelationship]:
>> org.ofbiz.entity.GenericEntityException: Error while inserting:
>> [GenericEntity:PartyRelationship][createdStamp,2008-06-06
>> 16:18:44.82(java.sql.Timestamp)][createdTxStamp,2008-06-06
>> 16:18:42.419(java.sql.Timestamp)][fromDate,2008-06-06
>> 16:18:44.811(java.sql.Timestamp)][lastUpdatedStamp,2008-06-06
>> 16:18:44.82(java.sql.Timestamp)][lastUpdatedTxStamp,2008-06-06
>> 16:18:42.419(java.sql.Timestamp)][partyIdTo,10210(java.lang.String)][roleTypeIdFrom,_NA_(java.lang.String)][roleTypeIdTo,CUSTOMER(java.lang.String)]
>> (SQL Exception while executing the following:INSERT INTO
>> public.PARTY_RELATIONSHIP (PARTY_ID_FROM, PARTY_ID_TO, ROLE_TYPE_ID_FROM,
>> ROLE_TYPE_ID_TO, FROM_DATE, THRU_DATE, STATUS_ID, RELATIONSHIP_NAME,
>> SECURITY_GROUP_ID, PRIORITY_TYPE_ID, PARTY_RELATIONSHIP_TYPE_ID,
>> PERMISSIONS_ENUM_ID, POSITION_TITLE, COMMENTS, LAST_UPDATED_STAMP,
>> LAST_UPDATED_TX_STAMP, CREATED_STAMP, CREATED_TX_STAMP) VALUES (?, ?, ?, ?,
>> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)(ERROR: null value in column
>> "party_id_from" violates not-null constraint)). Rolling back transaction.
>>
> is the description wrong, or my understanding of the description?
>
> Greetings,
> Roland
>
Reply | Threaded
Open this post in threaded view
|

Re: reusing service createPartyRelationship

RolandH-2
Hi Ashish,

i got it working, without manually setting the partyIdFrom:

Index: applications/party/script/org/ofbiz/party/party/PartyServices.xml
===================================================================
--- applications/party/script/org/ofbiz/party/party/PartyServices.xml    
(revision 665702)
+++ applications/party/script/org/ofbiz/party/party/PartyServices.xml    
(working copy)
@@ -766,6 +766,7 @@
     <simple-method method-name="createPartyRelationship"
short-description="createPartyRelationship">
         <if-empty field-name="parameters.roleTypeIdFrom"><set
field="parameters.roleTypeIdFrom" value="_NA_"/></if-empty>
         <if-empty field-name="parameters.roleTypeIdTo"><set
field="parameters.roleTypeIdTo" value="_NA_"/></if-empty>
+        <if-empty field-name="parameters.partyIdFrom"><set
field="parameters.partyIdFrom"
from-field="userLogin.partyId"/></if-empty>      
 
         <if-empty
field-name="parameters.fromDate"><now-timestamp-to-env
env-name="parameters.fromDate"/></if-empty>

should I post this to jira?      

Greetings,
Roland

Ashish Vijaywargiya wrote:

> You can take a help of the following URL to get more insight about the code
> :-
>
> https://localhost:8443/partymgr/control/EditPartyRelationships?partyId=admin
>
> Inside EditPartyRelationships.ftl file line # 103 partyIdFrom is passed as
> the hidden parameter to the service and the "partyId" has been set in the
> Screen definition.
> <input type="hidden" name="partyIdFrom" value="${partyId}"/>
>
> You may need to pass the partyIdFrom in your service map as its passed as
> the hidden field in the PartyRelationship screen that is present in Ofbiz.
> Please let us know if you are unable to find the way from my comments.
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: reusing service createPartyRelationship

Ashish Vijaywargiya
RolandH,

Thanks for your comments.
No need to create the JIRA issue for it.
I managed to update the code because it was of one line change.
Please take the update.

But we should note it down that it will be considered as "improvement"
instead of "BUG".

--
Ashish


On Mon, Jun 9, 2008 at 12:18 PM, RolandH <[hidden email]> wrote:

> Hi Ashish,
>
> i got it working, without manually setting the partyIdFrom:
>
> Index: applications/party/script/org/ofbiz/party/party/PartyServices.xml
> ===================================================================
> --- applications/party/script/org/ofbiz/party/party/PartyServices.xml
>  (revision 665702)
> +++ applications/party/script/org/ofbiz/party/party/PartyServices.xml
>  (working copy)
> @@ -766,6 +766,7 @@
>    <simple-method method-name="createPartyRelationship"
> short-description="createPartyRelationship">
>        <if-empty field-name="parameters.roleTypeIdFrom"><set
> field="parameters.roleTypeIdFrom" value="_NA_"/></if-empty>
>        <if-empty field-name="parameters.roleTypeIdTo"><set
> field="parameters.roleTypeIdTo" value="_NA_"/></if-empty>
> +        <if-empty field-name="parameters.partyIdFrom"><set
> field="parameters.partyIdFrom" from-field="userLogin.partyId"/></if-empty>
>
>        <if-empty field-name="parameters.fromDate"><now-timestamp-to-env
> env-name="parameters.fromDate"/></if-empty>
>
> should I post this to jira?
> Greetings,
> Roland
>
>
> Ashish Vijaywargiya wrote:
>
>> You can take a help of the following URL to get more insight about the
>> code
>> :-
>>
>>
>> https://localhost:8443/partymgr/control/EditPartyRelationships?partyId=admin
>>
>> Inside EditPartyRelationships.ftl file line # 103 partyIdFrom is passed as
>> the hidden parameter to the service and the "partyId" has been set in the
>> Screen definition.
>> <input type="hidden" name="partyIdFrom" value="${partyId}"/>
>>
>> You may need to pass the partyIdFrom in your service map as its passed as
>> the hidden field in the PartyRelationship screen that is present in Ofbiz.
>> Please let us know if you are unable to find the way from my comments.
>>
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: reusing service createPartyRelationship

RolandH-2
Hi Ashish,

yes, for sure that wasn't a bug. Here is another small improvment: make
externalId of Party entity useable through createPerson service:

Index: applications/party/servicedef/services.xml
===================================================================
--- applications/party/servicedef/services.xml    (revision 665986)
+++ applications/party/servicedef/services.xml    (working copy)
@@ -76,6 +76,7 @@
         <attribute name="statusId" type="String" mode="IN"
optional="true"/>
         <attribute name="preferredCurrencyUomId" type="String"
mode="IN" optional="true"/>
         <attribute name="description" type="String" mode="IN"
optional="true"/>
+        <attribute name="externalId" type="String" mode="IN"
optional="true"/>
         <override name="firstName" optional="false"/>
         <override name="lastName" optional="false"/>
     </service>
Index: applications/party/src/org/ofbiz/party/party/PartyServices.java
===================================================================
--- applications/party/src/org/ofbiz/party/party/PartyServices.java    
(revision 665986)
+++ applications/party/src/org/ofbiz/party/party/PartyServices.java    
(working copy)
@@ -144,7 +144,7 @@
             if (statusId == null) {
                 statusId = "PARTY_ENABLED";
             }
-            Map newPartyMap = UtilMisc.toMap("partyId", partyId,
"partyTypeId", "PERSON", "description", description, "createdDate", now,
"lastModifiedDate", now, "statusId", statusId);
+            Map newPartyMap = UtilMisc.toMap("partyId", partyId,
"partyTypeId", "PERSON", "description", description, "createdDate", now,
"lastModifiedDate", now, "statusId", statusId, "externalId",
context.get("externalId"));
             String preferredCurrencyUomId = (String)
context.get("preferredCurrencyUomId");
             if (!UtilValidate.isEmpty(preferredCurrencyUomId)) {
                 newPartyMap.put("preferredCurrencyUomId",
preferredCurrencyUomId);


And a new question :) [BTW: if you ever think RTFM is the right answer
to my questions, that's fine, please give me a hint of the correct manual]

I'm trying to get behind the idea of CountryCode entity in combination
with Geo entity...
my problem: I have to create PostalAddress with ISO 2 letter Country
Code, while PostalAddress requires a geoId.
The question right now is: what unique information does CountryCode
hold? why is it needed?
maybe Geo.geoCode is what I'm looking for?
Does a "fetch Geo where geoTypeId == 'COUNTRY' &&  Geo.geoSecCode is not
null && Geo.geoCode == isoCodeWeAreLookingFor " return the correct result?

Thanks again and again,
Roland

Ashish Vijaywargiya wrote:

> RolandH,
>
> Thanks for your comments.
> No need to create the JIRA issue for it.
> I managed to update the code because it was of one line change.
> Please take the update.
>
> But we should note it down that it will be considered as "improvement"
> instead of "BUG".
>  
Reply | Threaded
Open this post in threaded view
|

Re: reusing service createPartyRelationship

Ashish Vijaywargiya
Hello Roland,

Comments Inline :-

On Tue, Jun 10, 2008 at 11:48 AM, RolandH <[hidden email]> wrote:

> Hi Ashish,
>
> yes, for sure that wasn't a bug. Here is another small improvment: make
> externalId of Party entity useable through createPerson service:
>
> Index: applications/party/servicedef/services.xml
> ===================================================================
> --- applications/party/servicedef/services.xml    (revision 665986)
> +++ applications/party/servicedef/services.xml    (working copy)
> @@ -76,6 +76,7 @@
>        <attribute name="statusId" type="String" mode="IN" optional="true"/>
>        <attribute name="preferredCurrencyUomId" type="String" mode="IN"
> optional="true"/>
>        <attribute name="description" type="String" mode="IN"
> optional="true"/>
> +        <attribute name="externalId" type="String" mode="IN"
> optional="true"/>
>        <override name="firstName" optional="false"/>
>        <override name="lastName" optional="false"/>
>    </service>
> Index: applications/party/src/org/ofbiz/party/party/PartyServices.java
> ===================================================================
> --- applications/party/src/org/ofbiz/party/party/PartyServices.java
>  (revision 665986)
> +++ applications/party/src/org/ofbiz/party/party/PartyServices.java
>  (working copy)
> @@ -144,7 +144,7 @@
>            if (statusId == null) {
>                statusId = "PARTY_ENABLED";
>            }
> -            Map newPartyMap = UtilMisc.toMap("partyId", partyId,
> "partyTypeId", "PERSON", "description", description, "createdDate", now,
> "lastModifiedDate", now, "statusId", statusId);
> +            Map newPartyMap = UtilMisc.toMap("partyId", partyId,
> "partyTypeId", "PERSON", "description", description, "createdDate", now,
> "lastModifiedDate", now, "statusId", statusId, "externalId",
> context.get("externalId"));
>            String preferredCurrencyUomId = (String)
> context.get("preferredCurrencyUomId");
>            if (!UtilValidate.isEmpty(preferredCurrencyUomId)) {
>                newPartyMap.put("preferredCurrencyUomId",
> preferredCurrencyUomId);
>
>
I cann't update the use externalId in the createPerson service.
I remembered that there has been a discussion on ML long time back for not
keeping externalId on the createPerson service.

User can use this externalId in their own custom service.
I would like to see the community feedback on this then only can take
further action on it.


>
> And a new question :) [BTW: if you ever think RTFM is the right answer to
> my questions, that's fine, please give me a hint of the correct manual]


Its really hard for me to imagine that if you will not spend your time in
reading the document that is shared on Ofbiz Confluence then how should you
overcome
from the thing to ask question on ML instead of getting answer from your own
:-).


>
>
> I'm trying to get behind the idea of CountryCode entity in combination with
> Geo entity...
> my problem: I have to create PostalAddress with ISO 2 letter Country Code,
> while PostalAddress requires a geoId.


You can do one thing , Instead of creating the ISO 2 letter country code why
don't you fetch the associated "geoCode" (from Geo entity) related to the
"countryGeoId" value in PostalAddress in your custom code.
(PostalAddress(countryGeoId) --> Geo(geoId) )
This will be easy for you to maintain the code and keeping the code from
Ofbiz as it is.


> The question right now is: what unique information does CountryCode hold?
> why is it needed?


CountryCode entity is specific to the record for Country.
And at the same time Geo can hold the data related to Country & County etc.


>


> maybe Geo.geoCode is what I'm looking for?
> Does a "fetch Geo where geoTypeId == 'COUNTRY' &&  Geo.geoSecCode is not
> null && Geo.geoCode == isoCodeWeAreLookingFor " return the correct result?



From the PostalAddress record fetch the related record from Geo.
For example :- geoData = postalAddress.getRelatedOne("CountryGeo");
geoData.geoCode will return you the 2 Digit ISO code.

--
Ashish


>
>
> Thanks again and again,
> Roland
>
>
> Ashish Vijaywargiya wrote:
>
>> RolandH,
>>
>> Thanks for your comments.
>> No need to create the JIRA issue for it.
>> I managed to update the code because it was of one line change.
>> Please take the update.
>>
>> But we should note it down that it will be considered as "improvement"
>> instead of "BUG".
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: reusing service createPartyRelationship

RolandH-2
Hi Ashish,

comments see below:
> I cann't update the use externalId in the createPerson service.
> I remembered that there has been a discussion on ML long time back for not
> keeping externalId on the createPerson service.
>
> User can use this externalId in their own custom service.
> I would like to see the community feedback on this then only can take
> further action on it.
>  
I'm interested in comments, too. I've searched nabble but can't find
anything relating to this.

>> I'm trying to get behind the idea of CountryCode entity in combination with
>> Geo entity...
>> my problem: I have to create PostalAddress with ISO 2 letter Country Code,
>> while PostalAddress requires a geoId.
>>    
> You can do one thing , Instead of creating the ISO 2 letter country code why
> don't you fetch the associated "geoCode" (from Geo entity) related to the
> "countryGeoId" value in PostalAddress in your custom code.
> (PostalAddress(countryGeoId) --> Geo(geoId) )
> This will be easy for you to maintain the code and keeping the code from
> Ofbiz as it is.
>  
Yes, that direction is simple: getting ISO country code from
PostalAddress, but maybe I wasn't clear, i have to create a new
PostalAddress using a ISO country code. So i have to get an geoId via a
ISO country code.

Greetings,
Roland