in ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayFeedback.java [56:210]
public static Map<String, Object> loadFeedback(DispatchContext dctx, Map<String, ? extends Object> context) {
Map<String, Object> result = new HashMap<>();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Delegator delegator = dctx.getDelegator();
Locale locale = (Locale) context.get("locale");
String productStoreId = (String) context.get("productStoreId");
ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
try {
Map<String, Object> inMap = new HashMap<>();
inMap.put("productStoreId", productStoreId);
inMap.put("userLogin", userLogin);
Map<String, Object> resultUser = dispatcher.runSync("getEbayStoreUser", inMap);
if (ServiceUtil.isError(resultUser)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(resultUser));
}
String userID = (String) resultUser.get("userLoginId");
GetFeedbackCall feedbackCall = new GetFeedbackCall();
feedbackCall.setApiContext(apiContext);
SiteCodeType siteCodeType = EbayStoreHelper.getSiteCodeType(productStoreId, locale, delegator);
feedbackCall.setSite(siteCodeType);
feedbackCall.setUserID(userID);
DetailLevelCodeType[] detailLevelCodeType = {DetailLevelCodeType.RETURN_ALL};
feedbackCall.setDetailLevel(detailLevelCodeType);
FeedbackDetailType[] feedback = feedbackCall.getFeedback();
if (feedback != null) {
String partyId = null;
GenericValue userLoginEx = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", userID).queryOne();
if (userLoginEx == null) {
//Party
GenericValue party = delegator.makeValue("Party");
partyId = delegator.getNextSeqId("Party");
party.put("partyId", partyId);
party.put("partyTypeId", "PERSON");
party.create();
//UserLogin
userLoginEx = delegator.makeValue("UserLogin");
userLoginEx.put("userLoginId", userID);
userLoginEx.put("partyId", partyId);
userLoginEx.create();
} else {
partyId = userLoginEx.getString("partyId");
}
//PartyRole For eBay User
GenericValue ownerPartyRole = EntityQuery.use(delegator).from("PartyRole")
.where("partyId", partyId, "roleTypeId", "OWNER")
.queryOne();
if (UtilValidate.isEmpty(ownerPartyRole)) {
GenericValue partyRole = delegator.makeValue("PartyRole");
partyRole.put("partyId", partyId);
partyRole.put("roleTypeId", "OWNER");
partyRole.create();
}
int feedbackLength = feedback.length;
for (FeedbackDetailType feedbackDetailType : feedback) {
//convert to ofbiz
String contentId = feedbackDetailType.getFeedbackID();
Date eBayDateTime = feedbackDetailType.getCommentTime().getTime();
GenericValue contentCheck = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne();
if (contentCheck != null) {
continue;
}
String textData = feedbackDetailType.getCommentText();
String commentingUserId = feedbackDetailType.getCommentingUser();
String commentingPartyId = null;
GenericValue CommentingUserLogin = EntityQuery.use(delegator).from("UserLogin")
.where("userLoginId", commentingUserId)
.queryOne();
if (UtilValidate.isEmpty(CommentingUserLogin)) {
//Party
GenericValue party = delegator.makeValue("Party");
commentingPartyId = delegator.getNextSeqId("Party");
party.put("partyId", commentingPartyId);
party.put("partyTypeId", "PERSON");
party.create();
//UserLogin
userLoginEx = delegator.makeValue("UserLogin");
userLoginEx.put("userLoginId", commentingUserId);
userLoginEx.put("partyId", commentingPartyId);
userLoginEx.create();
} else {
commentingPartyId = CommentingUserLogin.getString("partyId");
}
//DataResource
GenericValue dataResource = delegator.makeValue("DataResource");
String dataResourceId = delegator.getNextSeqId("DataResource");
dataResource.put("dataResourceId", dataResourceId);
dataResource.put("dataResourceTypeId", "ELECTRONIC_TEXT");
dataResource.put("mimeTypeId", "text/html");
dataResource.create();
//ElectronicText
GenericValue electronicText = delegator.makeValue("ElectronicText");
electronicText.put("dataResourceId", dataResourceId);
electronicText.put("textData", textData);
electronicText.create();
//Content
GenericValue content = delegator.makeValue("Content");
content.put("contentId", contentId);
content.put("contentTypeId", "DOCUMENT");
content.put("dataResourceId", dataResourceId);
content.put("createdDate", UtilDateTime.toTimestamp(eBayDateTime));
content.create();
//ContentPurpose
GenericValue contentPurpose = delegator.makeValue("ContentPurpose");
contentPurpose.put("contentId", contentId);
contentPurpose.put("contentPurposeTypeId", "FEEDBACK");
contentPurpose.create();
//PartyRole For eBay Commentator
GenericValue commentingPartyRole = EntityQuery.use(delegator).from("PartyRole")
.where("partyId", commentingPartyId, "roleTypeId", "COMMENTATOR")
.queryOne();
if (UtilValidate.isEmpty(commentingPartyRole)) {
GenericValue partyRole = delegator.makeValue("PartyRole");
partyRole.put("partyId", commentingPartyId);
partyRole.put("roleTypeId", "COMMENTATOR");
partyRole.create();
}
//ContentRole for eBay User
GenericValue ownerContentRole = EntityQuery.use(delegator).from("ContentRole")
.where("partyId", partyId, "roleTypeId", "OWNER", "contentId", contentId)
.queryFirst();
if (UtilValidate.isEmpty(ownerContentRole)) {
GenericValue contentRole = delegator.makeValue("ContentRole");
contentRole.put("contentId", contentId);
contentRole.put("partyId", partyId);
contentRole.put("roleTypeId", "OWNER");
contentRole.put("fromDate", UtilDateTime.nowTimestamp());
contentRole.create();
}
//ContentRole for Commentator
GenericValue commentingContentRole = EntityQuery.use(delegator).from("ContentRole")
.where("partyId", commentingPartyId, "roleTypeId", "COMMENTATOR", "contentId", contentId)
.queryFirst();
if (UtilValidate.isEmpty(commentingContentRole)) {
GenericValue contentRole = delegator.makeValue("ContentRole");
contentRole.put("contentId", contentId);
contentRole.put("partyId", commentingPartyId);
contentRole.put("roleTypeId", "COMMENTATOR");
contentRole.put("fromDate", UtilDateTime.nowTimestamp());
contentRole.create();
}
}
}
} catch (ApiException e) {
result = ServiceUtil.returnError("ApiException ".concat(e.getMessage()));
} catch (SdkException e) {
result = ServiceUtil.returnError("SdkException ".concat(e.getMessage()));
} catch (Exception e) {
result = ServiceUtil.returnError("Exception ".concat(e.getMessage()));
}
String successMsg = UtilProperties.getMessage(RESOURCE, "EbayLoadEbayFeedbackSuccessful", locale);
result = ServiceUtil.returnSuccess(successMsg);
return result;
}