//context.put("targetOperations", targetOperations);
context.putAll(content);
if (contentExists) {
//targetOperations.add("CONTENT_UPDATE");
Map contentContext = FastMap.newInstance();
ModelService contentModel = dispatcher.getDispatchContext().getModelService("updateContent");
contentContext.putAll(contentModel.makeValid(content, "IN"));
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 thisResult = dispatcher.runSync("updateContent", contentContext);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult)) {
return ServiceUtil.returnError("Error updating content (updateContent) in persistContentAndAssoc", null, null, thisResult);
}
//Map thisResult = ContentServices.updateContentMethod(dctx, context);
} else {
//targetOperations.add("CONTENT_CREATE");
Map contentContext = FastMap.newInstance();
ModelService contentModel = dispatcher.getDispatchContext().getModelService("createContent");
contentContext.putAll(contentModel.makeValid(content, "IN"));
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 thisResult = dispatcher.runSync("createContent", contentContext);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult)) {
return ServiceUtil.returnError("Error creating content (createContent) in persistContentAndAssoc", null, null, thisResult);
}
//Map thisResult = ContentServices.createContentMethod(dctx, context);
contentId = (String) thisResult.get("contentId");
}
results.put("contentId", contentId);
context.put("contentId", contentId);
context.put("caContentIdTo", contentId);
contentAssoc.put("contentIdTo", contentId);
// Add ContentPurposes if this is a create operation
if (contentId != null && !contentExists) {
try {
if (contentPurposeList != null) {
Set contentPurposeSet = UtilMisc.makeSetWritable(contentPurposeList);
Iterator iter = contentPurposeSet.iterator();
while (iter.hasNext()) {
String contentPurposeTypeId = (String)iter.next();
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 map = FastMap.newInstance();
map.put("userLogin", userLogin);
map.put("dataResourceId", dataResourceId);
map.put("contentId", contentId);
if (Debug.infoOn()) Debug.logInfo("in persist... context:" + context, module);
Map 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));
}
}
// If parentContentIdTo or parentContentIdFrom exists, create association with newly created content
if (Debug.infoOn()) {
Debug.logInfo("CREATING contentASSOC contentAssocTypeId:" + contentAssocTypeId, null);
}
// create content assoc if the key values are present....
Debug.logInfo("contentAssoc: " + contentAssoc.toString(), null);
if (UtilValidate.isNotEmpty(contentAssocTypeId) && contentAssoc.get("contentId") != null && contentAssoc.get("contentIdTo") != null) {
if (Debug.infoOn())
Debug.logInfo("in persistContentAndAssoc, deactivateExisting:" + deactivateExisting, null);
Map contentAssocContext = FastMap.newInstance();
contentAssocContext.put("userLogin", userLogin);
contentAssocContext.put("displayFailCond", bDisplayFailCond);
contentAssocContext.put("skipPermissionCheck", context.get("skipPermissionCheck"));
Map thisResult = null;
try {
GenericValue contentAssocExisting = delegator.findByPrimaryKey("ContentAssoc", contentAssoc.getPrimaryKey());
if (contentAssocExisting == null) {
ModelService contentAssocModel = dispatcher.getDispatchContext().getModelService("createContentAssoc");
Map ctx = contentAssocModel.makeValid(contentAssoc, "IN");
contentAssocContext.putAll(ctx);
thisResult = dispatcher.runSync("createContentAssoc", contentAssocContext);
String errMsg = ServiceUtil.getErrorMessage(thisResult);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult) || UtilValidate.isNotEmpty(errMsg)) {
return ServiceUtil.returnError(errMsg);
}
// results.put("contentIdTo",
// thisResult.get("contentIdTo"));
// results.put("contentIdFrom",
// thisResult.get("contentIdFrom"));
// results.put("contentId",
// thisResult.get("contentIdFrom"));
// results.put("contentAssocTypeId",
// thisResult.get("contentAssocTypeId"));
// results.put("fromDate", thisResult.get("fromDate"));
// results.put("sequenceNum",
// thisResult.get("sequenceNum"));
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) {
contentAssoc.put("thruDate", UtilDateTime.nowTimestamp());
}
ModelService contentAssocModel = dispatcher.getDispatchContext().getModelService("updateContentAssoc");
Map ctx = contentAssocModel.makeValid(contentAssoc, "IN");
contentAssocContext.putAll(ctx);
thisResult = dispatcher.runSync("updateContentAssoc", contentAssocContext);
String errMsg = ServiceUtil.getErrorMessage(thisResult);
if (ServiceUtil.isError(thisResult) || ServiceUtil.isFailure(thisResult) || UtilValidate.isNotEmpty(errMsg)) {
return ServiceUtil.returnError(errMsg);