001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.channels.groupsmanager.commands;
007:
008: import org.jasig.portal.ChannelRuntimeData;
009: import org.jasig.portal.channels.groupsmanager.CGroupsManagerSessionData;
010: import org.jasig.portal.channels.groupsmanager.GroupsManagerXML;
011: import org.jasig.portal.channels.groupsmanager.Utility;
012: import org.jasig.portal.groups.ILockableEntityGroup;
013: import org.w3c.dom.Document;
014: import org.w3c.dom.Element;
015:
016: /**
017: * This class update the group with a new name. It then updates
018: * all of the xml elements with the new name.
019: * @author Don Fracapane
020: * @version $Revision: 35495 $
021: */
022: public class UpdateGroup extends GroupsManagerCommand {
023:
024: public UpdateGroup() {
025: }
026:
027: /**
028: * This is the public method
029: * @param sessionData
030: * @throws Exception
031: */
032: public void execute(CGroupsManagerSessionData sessionData)
033: throws Exception {
034: ChannelRuntimeData runtimeData = sessionData.runtimeData;
035: Utility.logMessage("DEBUG", "UpdateGroup::execute(): Start");
036: Document model = getXmlDoc(sessionData);
037: String newName = runtimeData.getParameter("grpName");
038: String newDescription = runtimeData
039: .getParameter("grpDescription");
040: String updId = getCommandArg(runtimeData);
041: Element updElem = GroupsManagerXML.getElementByTagNameAndId(
042: model, GROUP_TAGNAME, updId);
043: String retMsg;
044: String curName = GroupsManagerXML.getElementValueForTagName(
045: updElem, "dc:title");
046: if (curName == null || curName.equals("")) {
047: Utility.logMessage("ERROR",
048: "UpdateGroup::execute(): Cannot find dc:title element for: "
049: + updElem.getAttribute("name"));
050: return;
051: }
052: String curDescription = GroupsManagerXML
053: .getElementValueForTagName(updElem, "dc:description");
054: boolean hasChanged = false;
055: if (!Utility.areEqual(curName, newName)) {
056: Utility.logMessage("DEBUG",
057: "UpdateGroup::execute(): Group name: '" + curName
058: + "' will be updated to : '" + newName
059: + "'");
060: hasChanged = true;
061: }
062: if (!Utility.areEqual(curDescription, newDescription)) {
063: Utility.logMessage("DEBUG",
064: "UpdateGroup::execute(): Group: '" + newDescription
065: + "' will be updated to : '"
066: + newDescription + "'");
067: hasChanged = true;
068: }
069: // Notify user if nothing was changed
070: if (!hasChanged) {
071: Utility
072: .logMessage(
073: "DEBUG",
074: "UpdateGroup::execute(): Update was not applied because nothing has been changed.");
075: retMsg = "Update was not applied. No changes were entered.";
076: sessionData.feedback = retMsg;
077: return;
078: }
079: //IEntityGroup updGroup = GroupsManagerXML.retrieveGroup(updKey);
080: ILockableEntityGroup updGroup = sessionData.lockedGroup;
081: if (updGroup == null) {
082: retMsg = "Unable to retrieve Group!";
083: sessionData.feedback = retMsg;
084: return;
085: }
086: Utility.logMessage("DEBUG",
087: "UpdateGroup::execute(): About to update group: "
088: + curName);
089: updGroup.setName(newName);
090: updGroup.setDescription(newDescription);
091: updGroup.updateAndRenewLock();
092: Utility.logMessage("DEBUG",
093: "UpdateGroup::execute(): About to update xml nodes for group: "
094: + curName);
095: // update all xml nodes for this group
096: GroupsManagerXML.refreshAllNodes(sessionData
097: .getUnrestrictedData(), updGroup);
098: Utility.logMessage("DEBUG", "UpdateGroup::execute(): Finished");
099: }
100: }
|