use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class WorldPayEvents method worldPayNotify.
/**
* WorldPay notification
*/
public static String worldPayNotify(HttpServletRequest request, HttpServletResponse response) {
Locale locale = UtilHttp.getLocale(request);
Delegator delegator = (Delegator) request.getAttribute("delegator");
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
Map<String, Object> parametersMap = UtilHttp.getParameterMap(request);
String orderId = request.getParameter("cartId");
for (String name : parametersMap.keySet()) {
String value = request.getParameter(name);
Debug.logError("### Param: " + name + " => " + value, module);
}
// get the user
if (userLogin == null) {
String userLoginId = "system";
try {
userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", userLoginId).queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Cannot get UserLogin for: " + userLoginId + "; cannot continue", module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "worldPayEvents.problemsGettingAuthenticationUser", locale));
return "error";
}
}
// get the order header
GenericValue orderHeader = null;
if (UtilValidate.isNotEmpty(orderId)) {
try {
orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Cannot get the order header for order: " + orderId, module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "worldPayEvents.problemsGettingOrderHeader", locale));
return "error";
}
} else {
Debug.logError("WorldPay did not callback with a valid orderId!", module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "worldPayEvents.noValidOrderIdReturned", locale));
return "error";
}
if (orderHeader == null) {
Debug.logError("Cannot get the order header for order: " + orderId, module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "worldPayEvents.problemsGettingOrderHeader", locale));
return "error";
}
// get the transaction status
String paymentStatus = request.getParameter("transStatus");
// attempt to start a transaction
boolean okay = true;
boolean beganTransaction = false;
try {
beganTransaction = TransactionUtil.begin();
// authorized
if ("Y".equals(paymentStatus)) {
okay = OrderChangeHelper.approveOrder(dispatcher, userLogin, orderId);
// cancelled
} else if ("C".equals(paymentStatus)) {
okay = OrderChangeHelper.cancelOrder(dispatcher, userLogin, orderId);
}
if (okay) {
// set the payment preference
okay = setPaymentPreferences(delegator, dispatcher, userLogin, orderId, request);
}
} catch (Exception e) {
String errMsg = "Error handling WorldPay notification";
Debug.logError(e, errMsg, module);
try {
TransactionUtil.rollback(beganTransaction, errMsg, e);
} catch (GenericTransactionException gte2) {
Debug.logError(gte2, "Unable to rollback transaction", module);
}
} finally {
if (!okay) {
try {
TransactionUtil.rollback(beganTransaction, "Failure in processing WorldPay callback", null);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback transaction", module);
}
} else {
try {
TransactionUtil.commit(beganTransaction);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to commit transaction", module);
}
}
}
if (okay) {
// call the email confirm service
Map<String, Object> emailContext = UtilMisc.toMap("orderId", orderId, "userLogin", userLogin);
try {
dispatcher.runSync("sendOrderConfirmation", emailContext);
} catch (GenericServiceException e) {
Debug.logError(e, "Problems sending email confirmation", module);
}
}
return "success";
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class ContentManagementServices method updateSiteRolesDyn.
public static Map<String, Object> updateSiteRolesDyn(DispatchContext dctx, Map<String, ? extends Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
Map<String, Object> results = new HashMap<String, Object>();
Map<String, Object> thisResult = new HashMap<String, Object>();
Map<String, Object> serviceContext = new HashMap<String, Object>();
// siteContentId will equal "ADMIN_MASTER", "AGINC_MASTER", etc.
// Remember that this service is called in the "multi" mode,
// with a new siteContentId each time.
// siteContentId could also have been name deptContentId, since this same
// service is used for updating department roles, too.
String siteContentId = (String) context.get("contentId");
String partyId = (String) context.get("partyId");
serviceContext.put("partyId", partyId);
serviceContext.put("contentId", siteContentId);
List<GenericValue> siteRoles = null;
try {
siteRoles = EntityQuery.use(delegator).from("RoleType").where("parentTypeId", "BLOG").cache().queryList();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.toString());
}
for (GenericValue roleType : siteRoles) {
// BLOG_EDITOR, BLOG_ADMIN, etc.
String siteRole = (String) roleType.get("roleTypeId");
String cappedSiteRole = ModelUtil.dbNameToVarName(siteRole);
String siteRoleVal = (String) context.get(cappedSiteRole);
Object fromDate = context.get(cappedSiteRole + "FromDate");
serviceContext.put("roleTypeId", siteRole);
if (siteRoleVal != null && "Y".equalsIgnoreCase(siteRoleVal)) {
// for now, will assume that any error is due to duplicates - ignore
if (fromDate == null) {
try {
serviceContext.put("fromDate", UtilDateTime.nowTimestamp());
if (Debug.infoOn()) {
Debug.logInfo("updateSiteRoles, serviceContext(1):" + serviceContext, module);
}
addRoleToUser(delegator, dispatcher, serviceContext);
thisResult = dispatcher.runSync("createContentRole", serviceContext);
if (ServiceUtil.isError(thisResult)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
}
} catch (GenericServiceException e) {
Debug.logError(e, e.toString(), module);
} catch (Exception e2) {
Debug.logError(e2, e2.toString(), module);
}
}
} else {
if (fromDate != null) {
// return ServiceUtil.returnError(e.toString());
try {
Debug.logInfo("updateSiteRoles, serviceContext(2):" + serviceContext, module);
Map<String, Object> newContext = new HashMap<String, Object>();
newContext.put("contentId", serviceContext.get("contentId"));
newContext.put("partyId", serviceContext.get("partyId"));
newContext.put("roleTypeId", serviceContext.get("roleTypeId"));
thisResult = dispatcher.runSync("deactivateAllContentRoles", newContext);
if (ServiceUtil.isError(thisResult)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
}
} catch (GenericServiceException e) {
Debug.logError(e, e.toString(), module);
} catch (Exception e2) {
Debug.logError(e2, e2.toString(), module);
}
}
}
}
return results;
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class ContentManagementServices method persistContentAndAssoc.
/**
* persistContentAndAssoc
* A combination method that will create or update all or one of the following:
* a Content entity, a ContentAssoc related to the Content, and
* the ElectronicText that may be associated with the Content.
* The keys for determining if each entity is created is the presence
* of the contentTypeId, contentAssocTypeId and dataResourceTypeId.
* This service tries to handle DataResource fields with and
* without "dr" prefixes.
* Assumes binary data is always in field, "imageData".
*
* This service does not accept straight ContentAssoc parameters. They must be prefaced with "ca" + cap first letter
*/
public static Map<String, Object> persistContentAndAssoc(DispatchContext dctx, Map<String, ? extends Object> rcontext) throws GenericServiceException {
Delegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
Map<String, Object> context = UtilMisc.makeMapWritable(rcontext);
Locale locale = (Locale) context.get("locale");
// Knowing why a request fails permission check is one of the more difficult
// aspects of content management. Setting "displayFailCond" to true will
// put an html table in result.errorMessage that will show what tests were performed
Boolean bDisplayFailCond = (Boolean) context.get("displayFailCond");
String mapKey = (String) context.get("mapKey");
// If "deactivateExisting" is set, other Contents that are tied to the same
// contentIdTo will be deactivated (thruDate set to now)
String deactivateString = (String) context.get("deactivateExisting");
boolean deactivateExisting = "true".equalsIgnoreCase(deactivateString);
if (Debug.infoOn())
Debug.logInfo("in persist... mapKey(0):" + mapKey, module);
// ContentPurposes can get passed in as a delimited string or a list. Combine.
List<String> contentPurposeList = UtilGenerics.checkList(context.get("contentPurposeList"));
if (contentPurposeList == null) {
contentPurposeList = new LinkedList<String>();
}
String contentPurposeString = (String) context.get("contentPurposeString");
if (UtilValidate.isNotEmpty(contentPurposeString)) {
List<String> tmpPurposes = StringUtil.split(contentPurposeString, "|");
contentPurposeList.addAll(tmpPurposes);
}
if (contentPurposeList != null) {
context.put("contentPurposeList", contentPurposeList);
context.put("contentPurposeString", null);
}
if (Debug.infoOn()) {
Debug.logInfo("in persist... contentPurposeList(0):" + contentPurposeList, module);
Debug.logInfo("in persist... textData(0):" + context.get("textData"), module);
}
GenericValue content = delegator.makeValue("Content");
content.setPKFields(context);
content.setNonPKFields(context);
String contentId = (String) content.get("contentId");
String contentTypeId = (String) content.get("contentTypeId");
String origContentId = (String) content.get("contentId");
String origDataResourceId = (String) content.get("dataResourceId");
if (Debug.infoOn()) {
Debug.logInfo("in persist... contentId(0):" + contentId, module);
}
GenericValue dataResource = delegator.makeValue("DataResource");
dataResource.setPKFields(context);
dataResource.setNonPKFields(context);
dataResource.setAllFields(context, false, "dr", null);
String isPublic = (String) context.get("isPublic");
if (UtilValidate.isEmpty(isPublic)) {
dataResource.set("isPublic", "N");
}
context.putAll(dataResource);
String dataResourceId = (String) dataResource.get("dataResourceId");
String dataResourceTypeId = (String) dataResource.get("dataResourceTypeId");
if (Debug.infoOn()) {
Debug.logInfo("in persist... dataResourceId(0):" + dataResourceId, module);
}
GenericValue contentAssoc = delegator.makeValue("ContentAssoc");
String contentAssocTypeId = (String) context.get("contentAssocTypeId");
if (UtilValidate.isNotEmpty(contentAssocTypeId)) {
context.put("caContentAssocTypeId", contentAssocTypeId);
}
contentAssocTypeId = (String) context.get("caContentAssocTypeId");
contentAssoc.setAllFields(context, false, "ca", null);
contentAssoc.put("contentId", context.get("caContentId"));
context.putAll(contentAssoc);
GenericValue electronicText = delegator.makeValue("ElectronicText");
electronicText.setPKFields(context);
electronicText.setNonPKFields(context);
// save expected primary keys on result now in case there is no operation that uses them
Map<String, Object> results = ServiceUtil.returnSuccess();
results.put("contentId", content.get("contentId"));
results.put("dataResourceId", dataResource.get("dataResourceId"));
results.put("drDataResourceId", dataResource.get("dataResourceId"));
results.put("drDataResourceId", dataResource.get("dataResourceId"));
results.put("caContentIdTo", contentAssoc.get("contentIdTo"));
results.put("caContentId", contentAssoc.get("contentId"));
results.put("caFromDate", contentAssoc.get("fromDate"));
results.put("caContentAssocTypeId", contentAssoc.get("contentAssocTypeId"));
// get user info for multiple use
GenericValue userLogin = (GenericValue) context.get("userLogin");
boolean dataResourceExists = true;
if (Debug.infoOn()) {
Debug.logInfo("in persist... dataResourceTypeId(0):" + dataResourceTypeId, module);
}
if (UtilValidate.isNotEmpty(dataResourceTypeId)) {
Map<String, Object> dataResourceResult;
try {
dataResourceResult = persistDataResourceAndDataMethod(dctx, context);
} catch (GenericServiceException e) {
Debug.logError(e, e.toString(), module);
return ServiceUtil.returnError(e.toString());
} catch (GenericEntityException e) {
Debug.logError(e, e.toString(), module);
return ServiceUtil.returnError(e.toString());
} catch (Exception e) {
Debug.logError(e, e.toString(), module);
return ServiceUtil.returnError(e.toString());
}
String errorMsg = ServiceUtil.getErrorMessage(dataResourceResult);
if (UtilValidate.isNotEmpty(errorMsg)) {
return ServiceUtil.returnError(errorMsg);
}
dataResourceId = (String) dataResourceResult.get("dataResourceId");
results.put("dataResourceId", dataResourceId);
results.put("drDataResourceId", dataResourceId);
context.put("dataResourceId", dataResourceId);
content.put("dataResourceId", dataResourceId);
context.put("drDataResourceId", dataResourceId);
}
// Do update and create permission checks on Content if warranted.
// Force check here
context.put("skipPermissionCheck", null);
boolean contentExists = true;
if (Debug.infoOn()) {
Debug.logInfo("in persist... contentTypeId:" + contentTypeId + " dataResourceTypeId:" + dataResourceTypeId + " contentId:" + contentId + " dataResourceId:" + dataResourceId, module);
}
if (UtilValidate.isNotEmpty(contentTypeId)) {
if (UtilValidate.isEmpty(contentId)) {
contentExists = false;
} else {
try {
GenericValue val = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne();
if (val == null)
contentExists = false;
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.toString());
}
}
context.putAll(content);
if (contentExists) {
Map<String, Object> contentContext = new HashMap<String, Object>();
ModelService contentModel = dispatcher.getDispatchContext().getModelService("updateContent");
contentContext.putAll(contentModel.makeValid(content, ModelService.IN_PARAM));
contentContext.put("userLogin", userLogin);
contentContext.put("displayFailCond", bDisplayFailCond);
contentContext.put("skipPermissionCheck", context.get("skipPermissionCheck"));
Debug.logInfo("In persistContentAndAssoc calling updateContent with content: " + contentContext, module);
Map<String, Object> thisResult = dispatcher.runSync("updateContent", contentContext);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentContentUpdatingError", UtilMisc.toMap("serviceName", "persistContentAndAssoc"), locale), null, null, thisResult);
}
} else {
Map<String, Object> contentContext = new HashMap<String, Object>();
ModelService contentModel = dispatcher.getDispatchContext().getModelService("createContent");
contentContext.putAll(contentModel.makeValid(content, ModelService.IN_PARAM));
contentContext.put("userLogin", userLogin);
contentContext.put("displayFailCond", bDisplayFailCond);
contentContext.put("skipPermissionCheck", context.get("skipPermissionCheck"));
Debug.logInfo("In persistContentAndAssoc calling createContent with content: " + contentContext, module);
Map<String, Object> thisResult = dispatcher.runSync("createContent", contentContext);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentContentCreatingError", UtilMisc.toMap("serviceName", "persistContentAndAssoc"), locale), null, null, thisResult);
}
contentId = (String) thisResult.get("contentId");
}
results.put("contentId", contentId);
context.put("contentId", contentId);
context.put("caContentIdTo", contentId);
// Add ContentPurposes if this is a create operation
if (contentId != null && !contentExists) {
try {
Set<String> contentPurposeSet = UtilMisc.makeSetWritable(contentPurposeList);
for (String contentPurposeTypeId : contentPurposeSet) {
GenericValue contentPurpose = delegator.makeValue("ContentPurpose", UtilMisc.toMap("contentId", contentId, "contentPurposeTypeId", contentPurposeTypeId));
contentPurpose.create();
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.toString());
}
}
} else if (UtilValidate.isNotEmpty(dataResourceTypeId) && UtilValidate.isNotEmpty(contentId)) {
// If dataResource was not previously existing, then update the associated content with its id
if (UtilValidate.isNotEmpty(dataResourceId) && !dataResourceExists) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("userLogin", userLogin);
map.put("dataResourceId", dataResourceId);
map.put("contentId", contentId);
if (Debug.infoOn())
Debug.logInfo("in persist... context:" + context, module);
Map<String, Object> r = ContentServices.updateContentMethod(dctx, map);
boolean isError = ModelService.RESPOND_ERROR.equals(r.get(ModelService.RESPONSE_MESSAGE));
if (isError)
return ServiceUtil.returnError((String) r.get(ModelService.ERROR_MESSAGE));
}
}
// Put contentId
if (UtilValidate.isNotEmpty(contentId)) {
contentAssoc.put("contentIdTo", contentId);
}
// If parentContentIdTo or parentContentIdFrom exists, create association with newly created content
if (Debug.infoOn()) {
Debug.logInfo("CREATING contentASSOC contentAssocTypeId:" + contentAssocTypeId, module);
}
// create content assoc if the key values are present....
if (Debug.infoOn())
Debug.logInfo("contentAssoc: " + contentAssoc.toString(), module);
if (UtilValidate.isNotEmpty(contentAssocTypeId) && contentAssoc.get("contentId") != null && contentAssoc.get("contentIdTo") != null) {
if (Debug.infoOn())
Debug.logInfo("in persistContentAndAssoc, deactivateExisting:" + deactivateExisting, module);
Map<String, Object> contentAssocContext = new HashMap<String, Object>();
contentAssocContext.put("userLogin", userLogin);
contentAssocContext.put("displayFailCond", bDisplayFailCond);
contentAssocContext.put("skipPermissionCheck", context.get("skipPermissionCheck"));
Map<String, Object> thisResult = null;
try {
GenericValue contentAssocExisting = EntityQuery.use(delegator).from("ContentAssoc").where(contentAssoc.getPrimaryKey()).queryOne();
if (contentAssocExisting == null) {
ModelService contentAssocModel = dispatcher.getDispatchContext().getModelService("createContentAssoc");
Map<String, Object> ctx = contentAssocModel.makeValid(contentAssoc, ModelService.IN_PARAM);
contentAssocContext.putAll(ctx);
thisResult = dispatcher.runSync("createContentAssoc", contentAssocContext);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
}
results.put("caContentIdTo", thisResult.get("contentIdTo"));
results.put("caContentId", thisResult.get("contentIdFrom"));
results.put("caContentAssocTypeId", thisResult.get("contentAssocTypeId"));
results.put("caFromDate", thisResult.get("fromDate"));
results.put("caSequenceNum", thisResult.get("sequenceNum"));
} else {
if (deactivateExisting) {
contentAssocExisting.put("thruDate", UtilDateTime.nowTimestamp());
} else if (UtilValidate.isNotEmpty(context.get("thruDate"))) {
contentAssocExisting.put("thruDate", (Timestamp) context.get("thruDate"));
}
ModelService contentAssocModel = dispatcher.getDispatchContext().getModelService("updateContentAssoc");
Map<String, Object> ctx = contentAssocModel.makeValid(contentAssocExisting, ModelService.IN_PARAM);
contentAssocContext.putAll(ctx);
thisResult = dispatcher.runSync("updateContentAssoc", contentAssocContext);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
}
}
} catch (GenericEntityException e) {
throw new GenericServiceException(e.toString());
} catch (Exception e2) {
throw new GenericServiceException(e2.toString());
}
String errMsg = ServiceUtil.getErrorMessage(thisResult);
if (UtilValidate.isNotEmpty(errMsg)) {
return ServiceUtil.returnError(errMsg);
}
}
context.remove("skipPermissionCheck");
context.put("contentId", origContentId);
context.put("dataResourceId", origDataResourceId);
context.remove("dataResource");
Debug.logInfo("results:" + results, module);
return results;
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class ContentManagementServices method updateSiteRoles.
/**
* Service for update publish sites with a ContentRole that will tie them to the passed
* in party.
*/
public static Map<String, Object> updateSiteRoles(DispatchContext dctx, Map<String, ? extends Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Map<String, Object> results = new HashMap<String, Object>();
String siteContentId = (String) context.get("contentId");
String partyId = (String) context.get("partyId");
if (UtilValidate.isEmpty(siteContentId) || UtilValidate.isEmpty(partyId))
return results;
List<GenericValue> siteRoles = null;
try {
siteRoles = EntityQuery.use(delegator).from("RoleType").where("parentTypeId", "BLOG").cache().queryList();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.toString());
}
for (GenericValue roleType : siteRoles) {
Map<String, Object> serviceContext = new HashMap<String, Object>();
serviceContext.put("partyId", partyId);
serviceContext.put("contentId", siteContentId);
serviceContext.put("userLogin", userLogin);
Debug.logInfo("updateSiteRoles, serviceContext(0):" + serviceContext, module);
// BLOG_EDITOR, BLOG_ADMIN, etc.
String siteRole = (String) roleType.get("roleTypeId");
String cappedSiteRole = ModelUtil.dbNameToVarName(siteRole);
if (Debug.infoOn()) {
Debug.logInfo("updateSiteRoles, cappediteRole(1):" + cappedSiteRole, module);
}
String siteRoleVal = (String) context.get(cappedSiteRole);
if (Debug.infoOn()) {
Debug.logInfo("updateSiteRoles, siteRoleVal(1):" + siteRoleVal, module);
Debug.logInfo("updateSiteRoles, context(1):" + context, module);
}
Object fromDate = context.get(cappedSiteRole + "FromDate");
if (Debug.infoOn()) {
Debug.logInfo("updateSiteRoles, fromDate(1):" + fromDate, module);
}
serviceContext.put("roleTypeId", siteRole);
if (siteRoleVal != null && "Y".equalsIgnoreCase(siteRoleVal)) {
// for now, will assume that any error is due to duplicates - ignore
if (fromDate == null) {
try {
Map<String, Object> newContext = new HashMap<String, Object>();
newContext.put("contentId", serviceContext.get("contentId"));
newContext.put("partyId", serviceContext.get("partyId"));
newContext.put("roleTypeId", serviceContext.get("roleTypeId"));
newContext.put("userLogin", userLogin);
Map<String, Object> permResults = dispatcher.runSync("deactivateAllContentRoles", newContext);
if (ServiceUtil.isError(permResults)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(permResults));
}
serviceContext.put("fromDate", UtilDateTime.nowTimestamp());
if (Debug.infoOn())
Debug.logInfo("updateSiteRoles, serviceContext(1):" + serviceContext, module);
permResults = dispatcher.runSync("createContentRole", serviceContext);
if (ServiceUtil.isError(permResults)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(permResults));
}
} catch (GenericServiceException e) {
Debug.logError(e, e.toString(), module);
return ServiceUtil.returnError(e.toString());
} catch (Exception e2) {
Debug.logError(e2, e2.toString(), module);
return ServiceUtil.returnError(e2.toString());
}
}
} else {
if (fromDate != null) {
// for now, will assume that any error is due to non-existence - ignore
try {
Debug.logInfo("updateSiteRoles, serviceContext(2):" + serviceContext, module);
Map<String, Object> newContext = new HashMap<String, Object>();
newContext.put("contentId", serviceContext.get("contentId"));
newContext.put("partyId", serviceContext.get("partyId"));
newContext.put("roleTypeId", serviceContext.get("roleTypeId"));
newContext.put("userLogin", userLogin);
Map<String, Object> permResults = dispatcher.runSync("deactivateAllContentRoles", newContext);
if (ServiceUtil.isError(permResults)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(permResults));
}
} catch (GenericServiceException e) {
Debug.logError(e, e.toString(), module);
return ServiceUtil.returnError(e.toString());
} catch (Exception e2) {
Debug.logError(e2, e2.toString(), module);
return ServiceUtil.returnError(e2.toString());
}
}
}
}
return results;
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class ContentManagementServices method resequence.
public static Map<String, Object> resequence(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericServiceException {
Map<String, Object> result = new HashMap<String, Object>();
Delegator delegator = dctx.getDelegator();
String contentIdTo = (String) context.get("contentIdTo");
Integer seqInc = (Integer) context.get("seqInc");
if (seqInc == null) {
seqInc = Integer.valueOf(100);
}
int seqIncrement = seqInc.intValue();
List<String> typeList = UtilGenerics.checkList(context.get("typeList"));
if (typeList == null) {
typeList = new LinkedList<String>();
}
String contentAssocTypeId = (String) context.get("contentAssocTypeId");
if (UtilValidate.isNotEmpty(contentAssocTypeId)) {
typeList.add(contentAssocTypeId);
}
if (UtilValidate.isEmpty(typeList)) {
typeList = UtilMisc.toList("PUBLISH_LINK", "SUB_CONTENT");
}
EntityCondition conditionType = EntityCondition.makeCondition("contentAssocTypeId", EntityOperator.IN, typeList);
EntityCondition conditionMain = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("contentIdTo", EntityOperator.EQUALS, contentIdTo), conditionType), EntityOperator.AND);
try {
List<GenericValue> listAll = EntityQuery.use(delegator).from("ContentAssoc").where(conditionMain).orderBy("sequenceNum", "fromDate", "createdDate").filterByDate().queryList();
String contentId = (String) context.get("contentId");
String dir = (String) context.get("dir");
int seqNum = seqIncrement;
String thisContentId = null;
for (int i = 0; i < listAll.size(); i++) {
GenericValue contentAssoc = listAll.get(i);
if (UtilValidate.isNotEmpty(contentId) && UtilValidate.isNotEmpty(dir)) {
// move targeted entry up or down
thisContentId = contentAssoc.getString("contentId");
if (contentId.equals(thisContentId)) {
if (dir.startsWith("up")) {
if (i > 0) {
// Swap with previous entry
try {
GenericValue prevValue = listAll.get(i - 1);
Long prevSeqNum = (Long) prevValue.get("sequenceNum");
prevValue.put("sequenceNum", Long.valueOf(seqNum));
prevValue.store();
contentAssoc.put("sequenceNum", prevSeqNum);
contentAssoc.store();
} catch (Exception e) {
return ServiceUtil.returnError(e.toString());
}
}
} else {
if (i < listAll.size()) {
// Swap with next entry
GenericValue nextValue = listAll.get(i + 1);
nextValue.put("sequenceNum", Long.valueOf(seqNum));
nextValue.store();
seqNum += seqIncrement;
contentAssoc.put("sequenceNum", Long.valueOf(seqNum));
contentAssoc.store();
// skip next one
i++;
}
}
} else {
contentAssoc.put("sequenceNum", Long.valueOf(seqNum));
contentAssoc.store();
}
} else {
contentAssoc.put("sequenceNum", Long.valueOf(seqNum));
contentAssoc.store();
}
seqNum += seqIncrement;
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.toString());
}
return result;
}
Aggregations