0001: /***************************************************************
0002: * This file is part of the [fleXive](R) project.
0003: *
0004: * Copyright (c) 1999-2007
0005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
0006: * All rights reserved
0007: *
0008: * The [fleXive](R) project is free software; you can redistribute
0009: * it and/or modify it under the terms of the GNU General Public
0010: * License as published by the Free Software Foundation;
0011: * either version 2 of the License, or (at your option) any
0012: * later version.
0013: *
0014: * The GNU General Public License can be found at
0015: * http://www.gnu.org/copyleft/gpl.html.
0016: * A copy is found in the textfile GPL.txt and important notices to the
0017: * license from the author are found in LICENSE.txt distributed with
0018: * these libraries.
0019: *
0020: * This library is distributed in the hope that it will be useful,
0021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0023: * GNU General Public License for more details.
0024: *
0025: * For further information about UCS - unique computing solutions gmbh,
0026: * please see the company website: http://www.ucs.at
0027: *
0028: * For further information about [fleXive](R), please see the
0029: * project website: http://www.flexive.org
0030: *
0031: *
0032: * This copyright notice MUST APPEAR in all copies of the file!
0033: ***************************************************************/package com.flexive.war.beans.admin.structure;
0034:
0035: import com.flexive.faces.FxJsfUtils;
0036: import com.flexive.faces.beans.ActionBean;
0037: import com.flexive.faces.messages.FxFacesMsgErr;
0038: import com.flexive.faces.messages.FxFacesMsgInfo;
0039: import com.flexive.shared.*;
0040: import com.flexive.shared.scripting.FxScriptInfo;
0041: import com.flexive.shared.exceptions.FxApplicationException;
0042: import com.flexive.shared.security.ACL;
0043: import com.flexive.shared.security.UserTicket;
0044: import com.flexive.shared.security.Role;
0045: import com.flexive.shared.structure.*;
0046: import com.flexive.shared.value.FxString;
0047: import com.flexive.shared.value.FxValue;
0048: import com.flexive.war.javascript.tree.StructureTreeWriter;
0049: import org.apache.commons.lang.StringUtils;
0050: import org.apache.commons.logging.Log;
0051: import org.apache.commons.logging.LogFactory;
0052:
0053: import javax.faces.model.SelectItem;
0054: import java.util.ArrayList;
0055: import java.util.List;
0056: import java.util.Map;
0057: import java.util.HashMap;
0058:
0059: /**
0060: * Bean behind propertyAssignmentEditor.xhtml, propertyEditor.xhtml and propertyOptionEditor to
0061: * edit FxPropertyAssignment and FxProperty objects
0062: *
0063: * @author Gerhard Glos (gerhard.glos@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
0064: */
0065:
0066: public class PropertyEditorBean implements ActionBean {
0067: private static final Log LOG = LogFactory
0068: .getLog(PropertyEditorBean.class);
0069: //private String gotoPropertyAssignment = null;
0070: private long propertyId = -1;
0071: private FxLanguage defaultLanguage = null;
0072: private String assignmentOptionValue = null;
0073: private String assignmentOptionKey = null;
0074: private String propertyOptionValue = null;
0075: private String propertyOptionKey = null;
0076: private boolean propertyOptionOverridable = true;
0077: private OptionWrapper.WrappedOption optionFiler = null;
0078: FxPropertyAssignmentEdit assignment = null;
0079: private String minMultiplicity = null;
0080: private String maxMultiplicity = null;
0081: private String propertyMinMultiplicity = null;
0082: private String propertyMaxMultiplicity = null;
0083: private OptionWrapper optionWrapper = null;
0084: //private boolean allowDefaultLanguage = false;
0085: private FxPropertyEdit property = null;
0086: private String parentXPath = null;
0087: private FxType parentType = null;
0088: //checker to restore system language
0089: private boolean originalLanguageSystemLanguage = false;
0090: //checker if current user may edit the property
0091: private boolean structureManagement = false;
0092: //checker for the editMode: if not in edit mode,
0093: // save and delete buttons are not rendered by the gui
0094: private boolean editMode = false;
0095: //assignment script editor tab
0096: private ScriptListWrapper scriptWrapper = null;
0097: private int scriptListFiler = -1;
0098: private FxScriptInfo selectedScriptInfo = null;
0099: private long selectedScriptEventId = -1;
0100: private boolean selectedDerivedUsage = false;
0101: private boolean selectedActive = true;
0102: private int defaultMultiplicity = -1;
0103:
0104: /*
0105: public String getGotoPropertyAssignment() {
0106: return gotoPropertyAssignment;
0107: }
0108: */
0109: /*
0110: public void setGotoPropertyAssignment(String gotoPropertyAssignment) {
0111: this.gotoPropertyAssignment = gotoPropertyAssignment;
0112: }
0113: */
0114:
0115: public boolean isSystemInternal() {
0116: return property.isSystemInternal();
0117: }
0118:
0119: public boolean isPropertyMayOverrideACL() {
0120: return property.mayOverrideACL();
0121: }
0122:
0123: public void setPropertyMayOverrideACL(boolean b) {
0124: property.setOverrideACL(b);
0125: }
0126:
0127: public boolean isPropertyMayOverrideBaseMultiplicity() {
0128: return property.mayOverrideBaseMultiplicity();
0129: }
0130:
0131: public void setPropertyMayOverrideBaseMultiplicity(boolean b) {
0132: property.setOverrideMultiplicity(b);
0133: }
0134:
0135: public FxPropertyEdit getProperty() {
0136: return property;
0137: }
0138:
0139: public void setProperty(FxPropertyEdit property) {
0140: this .property = property;
0141: }
0142:
0143: public void setAcl(long aclid) {
0144: try {
0145: assignment
0146: .setACL(CacheAdmin.getEnvironment().getACL(aclid));
0147: } catch (Throwable t) {
0148: new FxFacesMsgErr(t).addToContext();
0149: }
0150: }
0151:
0152: public long getPropertyAcl() {
0153: return getProperty().getACL().getId();
0154: }
0155:
0156: public void setPropertyAcl(long aclid) {
0157: try {
0158: getProperty().setACL(
0159: CacheAdmin.getEnvironment().getACL(aclid));
0160: } catch (Throwable t) {
0161: new FxFacesMsgErr(t).addToContext();
0162: }
0163: }
0164:
0165: public long getAcl() {
0166: return assignment.getACL().getId();
0167: }
0168:
0169: public String getAlias() {
0170: return assignment.getAlias();
0171: }
0172:
0173: public void setAlias(String alias) {
0174: try {
0175: assignment.setAlias(alias);
0176: } catch (Throwable t) {
0177: new FxFacesMsgErr(t).addToContext();
0178: }
0179: }
0180:
0181: public int getDefaultMultiplicity() {
0182: return defaultMultiplicity;
0183: }
0184:
0185: public void setDefaultMultiplicity(int defaultMultiplicity) {
0186: this .defaultMultiplicity = defaultMultiplicity;
0187: }
0188:
0189: public FxValue getDefaultValue() {
0190: return assignment.getDefaultValue();
0191: }
0192:
0193: public void setDefaultValue(FxValue val) {
0194: try {
0195: assignment.setDefaultValue(val);
0196: } catch (Throwable t) {
0197: new FxFacesMsgErr(t).addToContext();
0198: }
0199: }
0200:
0201: public FxString getDefaultLabel() {
0202: return assignment.getDisplayLabel();
0203: }
0204:
0205: public void setDefaultLabel(FxString label) {
0206: try {
0207: assignment.setLabel(label);
0208: } catch (Throwable t) {
0209: new FxFacesMsgErr(t).addToContext();
0210: }
0211: }
0212:
0213: public FxString getLabel() {
0214: return assignment.getLabel();
0215: }
0216:
0217: public void setLabel(FxString label) {
0218: try {
0219: assignment.setLabel(label);
0220: } catch (Throwable t) {
0221: new FxFacesMsgErr(t).addToContext();
0222: }
0223: }
0224:
0225: public FxString getPropertyLabel() {
0226: return getProperty().getLabel();
0227: }
0228:
0229: public void setPropertyLabel(FxString label) {
0230: try {
0231: getProperty().setLabel(label);
0232: } catch (Throwable t) {
0233: new FxFacesMsgErr(t).addToContext();
0234: }
0235: }
0236:
0237: public boolean isEnabled() {
0238: return assignment.isEnabled();
0239: }
0240:
0241: public void setEnabled(boolean b) {
0242: assignment.setEnabled(b);
0243: }
0244:
0245: public FxString getHint() {
0246: return assignment.getHint();
0247: }
0248:
0249: public void setHint(FxString hint) {
0250: try {
0251: assignment.setHint(hint);
0252: } catch (Throwable t) {
0253: new FxFacesMsgErr(t).addToContext();
0254: }
0255: }
0256:
0257: public FxString getPropertyHint() {
0258: return getProperty().getHint();
0259: }
0260:
0261: public void setPropertyHint(FxString hint) {
0262: try {
0263: getProperty().setHint(hint);
0264: } catch (Throwable t) {
0265: new FxFacesMsgErr(t).addToContext();
0266: }
0267: }
0268:
0269: public String getPropertyName() {
0270: return getProperty().getName();
0271: }
0272:
0273: public void setPropertyName(String name) {
0274: try {
0275: getProperty().setName(name);
0276: } catch (Throwable t) {
0277: new FxFacesMsgErr(t).addToContext();
0278: }
0279: }
0280:
0281: public String getMinMultiplicity() {
0282: return minMultiplicity;
0283: }
0284:
0285: public void setMinMultiplicity(String minMultiplicity) {
0286: this .minMultiplicity = minMultiplicity;
0287: }
0288:
0289: public String getMaxMultiplicity() {
0290: return maxMultiplicity;
0291: }
0292:
0293: public void setMaxMultiplicity(String maxMultiplicity) {
0294: this .maxMultiplicity = maxMultiplicity;
0295: }
0296:
0297: public String getPropertyMinMultiplicity() {
0298: return propertyMinMultiplicity;
0299: }
0300:
0301: public void setPropertyMinMultiplicity(String minMultiplicity) {
0302: this .propertyMinMultiplicity = minMultiplicity;
0303: }
0304:
0305: public String getPropertyMaxMultiplicity() {
0306: return propertyMaxMultiplicity;
0307: }
0308:
0309: public void setPropertyMaxMultiplicity(String maxMultiplicity) {
0310: this .propertyMaxMultiplicity = maxMultiplicity;
0311: }
0312:
0313: public OptionWrapper.WrappedOption getOptionFiler() {
0314: return optionFiler;
0315: }
0316:
0317: public void setOptionFiler(OptionWrapper.WrappedOption optionFiler) {
0318: this .optionFiler = optionFiler;
0319: }
0320:
0321: public FxPropertyAssignmentEdit getAssignment() {
0322: return assignment;
0323: }
0324:
0325: public FxLanguage getDefaultLanguage() {
0326: return defaultLanguage;
0327: }
0328:
0329: public void setDefaultLanguage(FxLanguage defaultLanguage) {
0330: this .defaultLanguage = defaultLanguage;
0331: }
0332:
0333: public void setAssignment(FxPropertyAssignmentEdit assignment) {
0334: this .assignment = assignment;
0335: }
0336:
0337: public FxDataType getPropertyDataType() {
0338: return getProperty().getDataType();
0339: }
0340:
0341: /**
0342: * Set the property's data type and update referenced type and referenced list accordingly
0343: *
0344: * @param d the data type
0345: */
0346: public void setPropertyDataType(FxDataType d) {
0347: getProperty().setDataType(d);
0348: if (!isPropertySelectList()
0349: && getPropertyReferencedList() != -1) {
0350: setPropertyReferencedList(-1);
0351: }
0352: if (!isPropertyReference() && getPropertyReferencedType() != -1) {
0353: setPropertyReferencedType(-1);
0354: }
0355: }
0356:
0357: public boolean isPropertyFulltextIndexed() {
0358: return getProperty().isFulltextIndexed();
0359: }
0360:
0361: public void setPropertyFulltextIndexed(boolean b) {
0362: getProperty().setFulltextIndexed(b);
0363: }
0364:
0365: public boolean isPropertyAutoUniquePropertyName() {
0366: return getProperty().isAutoUniquePropertyName();
0367: }
0368:
0369: public void setPropertyAutoUniquePropertyName(boolean b) {
0370: getProperty().setAutoUniquePropertyName(b);
0371: }
0372:
0373: public UniqueMode getPropertyUniqueMode() {
0374: return getProperty().getUniqueMode();
0375: }
0376:
0377: public boolean isPropertyUsedInInstance() {
0378: boolean result = true;
0379: try {
0380: result = !property.isNew()
0381: && (EJBLookup.getAssignmentEngine()
0382: .getPropertyInstanceCount(propertyId) > 0);
0383: } catch (Throwable t) {
0384: new FxFacesMsgErr(t).addToContext();
0385: }
0386: return result;
0387: }
0388:
0389: public void setPropertyUniqueMode(UniqueMode u) {
0390: getProperty().setUniqueMode(u);
0391: }
0392:
0393: public long getPropertyReferencedList() {
0394: if (property.getReferencedList() == null) {
0395: return -1;
0396: }
0397: return property.getReferencedList().getId();
0398: }
0399:
0400: public void setPropertyReferencedList(long id) {
0401: if (id == -1) {
0402: property.setReferencedList(null);
0403: } else {
0404: property.setReferencedList(CacheAdmin.getEnvironment()
0405: .getSelectList(id));
0406: }
0407: }
0408:
0409: public boolean getPropertyHasReferencedType() {
0410: return property.hasReferencedType();
0411: }
0412:
0413: public long getPropertyReferencedType() {
0414: if (getProperty().getReferencedType() != null) {
0415: return getProperty().getReferencedType().getId();
0416: } else
0417: return -1;
0418: }
0419:
0420: /**
0421: * Returns a all available Types as List<SelectItem> and adds an empty element for null.
0422: *
0423: * @return available Types including a dummy value for null.
0424: */
0425: public List<SelectItem> getTypes() {
0426: List<FxType> typesList = CacheAdmin.getFilteredEnvironment()
0427: .getTypes(true, true, true, false);
0428: final List<SelectItem> result = new ArrayList<SelectItem>(
0429: typesList.size() + 1);
0430: final UserTicket ticket = FxContext.get().getTicket();
0431: result.add(new SelectItem((long) -1, ""));
0432: for (SelectableObjectWithLabel item : typesList) {
0433: result.add(new SelectItem(item.getId(), item.getLabel()
0434: .getBestTranslation(ticket)));
0435: }
0436: return result;
0437: }
0438:
0439: public void setPropertyReferencedType(long id) {
0440: if (id != -1) {
0441: getProperty().setReferencedType(
0442: CacheAdmin.getEnvironment().getType(id));
0443: } else {
0444: getProperty().setReferencedType(null);
0445: }
0446: }
0447:
0448: public long getPropertyId() {
0449: return propertyId;
0450: }
0451:
0452: public void setPropertyId(long propertyId) {
0453: this .propertyId = propertyId;
0454: }
0455:
0456: public String getAssignmentOptionValue() {
0457: return assignmentOptionValue;
0458: }
0459:
0460: public void setAssignmentOptionValue(String optionValue) {
0461: this .assignmentOptionValue = optionValue;
0462: }
0463:
0464: public String getAssignmentOptionKey() {
0465: return assignmentOptionKey;
0466: }
0467:
0468: public void setAssignmentOptionKey(String optionKey) {
0469: this .assignmentOptionKey = optionKey;
0470: }
0471:
0472: public boolean isPropertyOptionOverridable() {
0473: return propertyOptionOverridable;
0474: }
0475:
0476: public void setPropertyOptionOverridable(
0477: boolean propertyOptionOverridable) {
0478: this .propertyOptionOverridable = propertyOptionOverridable;
0479: }
0480:
0481: public void addAssignmentOption() {
0482: try {
0483: optionWrapper.addOption(optionWrapper
0484: .getAssignmentOptions(), assignmentOptionKey,
0485: assignmentOptionValue, false);
0486: assignmentOptionKey = null;
0487: assignmentOptionValue = null;
0488: } catch (Throwable t) {
0489: new FxFacesMsgErr(t).addToContext();
0490: }
0491: }
0492:
0493: public String getPropertyOptionValue() {
0494: return propertyOptionValue;
0495: }
0496:
0497: public void setPropertyOptionValue(String propertyOptionValue) {
0498: this .propertyOptionValue = propertyOptionValue;
0499: }
0500:
0501: public String getPropertyOptionKey() {
0502: return propertyOptionKey;
0503: }
0504:
0505: public void setPropertyOptionKey(String propertyOptionKey) {
0506: this .propertyOptionKey = propertyOptionKey;
0507: }
0508:
0509: public void addPropertyOption() {
0510: try {
0511: optionWrapper.addOption(
0512: optionWrapper.getStructureOptions(),
0513: propertyOptionKey, propertyOptionValue,
0514: propertyOptionOverridable);
0515: propertyOptionKey = null;
0516: propertyOptionValue = null;
0517: propertyOptionOverridable = true;
0518: } catch (Throwable t) {
0519: new FxFacesMsgErr(t).addToContext();
0520: }
0521: }
0522:
0523: public void deleteAssignmentOption() {
0524: optionWrapper.deleteOption(
0525: optionWrapper.getAssignmentOptions(), optionFiler);
0526: }
0527:
0528: public void deletePropertyOption() {
0529: optionWrapper.deleteOption(optionWrapper.getStructureOptions(),
0530: optionFiler);
0531: }
0532:
0533: public OptionWrapper getOptionWrapper() {
0534: return optionWrapper;
0535: }
0536:
0537: /**
0538: * Hack in order to use command buttons to submit the form values
0539: * and update the view of GUI elements
0540: */
0541: public void doNothing() {
0542: }
0543:
0544: /**
0545: * Returns all property assignments that are referencing this property which the
0546: * current user may see, excluding the system internal assignments.
0547: *
0548: * @return a list of property assignments that are referencing this property.
0549: */
0550: public List<FxPropertyAssignment> getReferencingPropertyAssignments() {
0551: List<FxPropertyAssignment> assignments = CacheAdmin
0552: .getFilteredEnvironment().getPropertyAssignments(true);
0553: List<FxPropertyAssignment> result = new ArrayList<FxPropertyAssignment>();
0554: for (FxPropertyAssignment assignment : assignments) {
0555: if (assignment.getProperty().getId() == property.getId()
0556: && !assignment.isSystemInternal()) {
0557: result.add(assignment);
0558: }
0559: }
0560: return result;
0561: }
0562:
0563: /**
0564: * If the assignment is derived, return the base assignments XPath
0565: *
0566: * @return the base assignments XPath if derived
0567: */
0568: public String getBaseAssignmentXPath() {
0569: if (assignment.isDerivedAssignment())
0570: return CacheAdmin.getEnvironment().getAssignment(
0571: assignment.getBaseAssignmentId()).getXPath();
0572: else
0573: return "";
0574: }
0575:
0576: public boolean isPropertyMayOverrideMultiLang() {
0577: return optionWrapper.getOption(true,
0578: FxStructureOption.OPTION_MULTILANG).isOverridable();
0579: }
0580:
0581: /**
0582: * Returns if the generic option FxStructureOption.OPTION_MULTILANG is set.
0583: * This option controls the multilingualism of a property.
0584: *
0585: * @return true if the generic option FxStructureOption.OPTION_MULTILANG is set.
0586: */
0587:
0588: public boolean isMultiLang() {
0589: if (!optionWrapper.getOption(true,
0590: FxStructureOption.OPTION_MULTILANG).getBooleanValue()) {
0591: if (!isPropertyMayOverrideMultiLang()
0592: || (isPropertyMayOverrideMultiLang() && !optionWrapper
0593: .hasOption(optionWrapper
0594: .getAssignmentOptions(),
0595: FxStructureOption.OPTION_MULTILANG))
0596: || (isPropertyMayOverrideMultiLang() && !optionWrapper
0597: .getOption(false,
0598: FxStructureOption.OPTION_MULTILANG)
0599: .getBooleanValue()))
0600: return false;
0601: } else {
0602: if (isPropertyMayOverrideMultiLang()
0603: && optionWrapper.hasOption(optionWrapper
0604: .getAssignmentOptions(),
0605: FxStructureOption.OPTION_MULTILANG)
0606: && !optionWrapper.getOption(false,
0607: FxStructureOption.OPTION_MULTILANG)
0608: .getBooleanValue())
0609: return false;
0610: }
0611: return true;
0612: }
0613:
0614: /**
0615: * Sets the FxStructureOption.OPTION_MULTILANG option defensively by considering
0616: * option overriding.
0617: * @param b boolean to set the option
0618: */
0619: public void setMultiLang(boolean b) {
0620: if (b) {
0621: if (isPropertyMayOverrideMultiLang()
0622: && optionWrapper.getOption(true,
0623: FxStructureOption.OPTION_MULTILANG)
0624: .getBooleanValue()) {
0625: optionWrapper.deleteOption(optionWrapper
0626: .getAssignmentOptions(), optionWrapper
0627: .getOption(false,
0628: FxStructureOption.OPTION_MULTILANG));
0629: } else if (isPropertyMayOverrideMultiLang()
0630: && !optionWrapper.getOption(true,
0631: FxStructureOption.OPTION_MULTILANG)
0632: .getBooleanValue()) {
0633: optionWrapper.setOption(false,
0634: FxStructureOption.OPTION_MULTILANG, b);
0635: } else if (!isPropertyMayOverrideMultiLang()
0636: && !optionWrapper.getOption(true,
0637: FxStructureOption.OPTION_MULTILANG)
0638: .getBooleanValue()) {
0639: optionWrapper.getOption(true,
0640: FxStructureOption.OPTION_MULTILANG)
0641: .setOverridable(true);
0642: optionWrapper.setOption(false,
0643: FxStructureOption.OPTION_MULTILANG, b);
0644: } else
0645: optionWrapper.deleteOption(optionWrapper
0646: .getAssignmentOptions(), optionWrapper
0647: .getOption(false,
0648: FxStructureOption.OPTION_MULTILANG));
0649: } else {
0650: if (isPropertyMayOverrideMultiLang()
0651: && optionWrapper.getOption(true,
0652: FxStructureOption.OPTION_MULTILANG)
0653: .getBooleanValue())
0654: optionWrapper.setOption(false,
0655: FxStructureOption.OPTION_MULTILANG, b);
0656: else if (isPropertyMayOverrideMultiLang()
0657: && !optionWrapper.getOption(true,
0658: FxStructureOption.OPTION_MULTILANG)
0659: .getBooleanValue())
0660: optionWrapper.deleteOption(optionWrapper
0661: .getAssignmentOptions(), optionWrapper
0662: .getOption(false,
0663: FxStructureOption.OPTION_MULTILANG));
0664: else if (!isPropertyMayOverrideMultiLang()
0665: && optionWrapper.getOption(true,
0666: FxStructureOption.OPTION_MULTILANG)
0667: .getBooleanValue()) {
0668: optionWrapper.getOption(true,
0669: FxStructureOption.OPTION_MULTILANG)
0670: .setOverridable(true);
0671: optionWrapper.setOption(false,
0672: FxStructureOption.OPTION_MULTILANG, b);
0673: } else
0674: optionWrapper.deleteOption(optionWrapper
0675: .getAssignmentOptions(), optionWrapper
0676: .getOption(false,
0677: FxStructureOption.OPTION_MULTILANG));
0678: }
0679: }
0680:
0681: public String getParseRequestParameters() {
0682: try {
0683: String action = FxJsfUtils.getParameter("action");
0684: if (StringUtils.isBlank(action)) {
0685: return null;
0686: } else if ("openInstance".equals(action)) {
0687: editMode = false;
0688: long propId = FxJsfUtils.getLongParameter("id", -1);
0689: setPropertyId(propId);
0690: FxPropertyAssignmentEdit assignment = ((FxPropertyAssignment) CacheAdmin
0691: .getEnvironment().getAssignment(propId))
0692: .asEditable();
0693: setAssignment(assignment);
0694: setProperty(assignment.getPropertyEdit());
0695: initEditing();
0696: } else if ("editInstance".equals(action)) {
0697: editMode = true;
0698: long propId = FxJsfUtils.getLongParameter("id", -1);
0699: setPropertyId(propId);
0700: FxPropertyAssignmentEdit assignment = ((FxPropertyAssignment) CacheAdmin
0701: .getEnvironment().getAssignment(propId))
0702: .asEditable();
0703: setAssignment(assignment);
0704: setProperty(assignment.getPropertyEdit());
0705: initEditing();
0706: } else if ("createProperty".equals(action)) {
0707: editMode = true;
0708: assignment = null;
0709: parentXPath = null;
0710: parentType = null;
0711: originalLanguageSystemLanguage = false;
0712:
0713: long id = FxJsfUtils.getLongParameter("id");
0714: String nodeType = FxJsfUtils.getParameter("nodeType");
0715:
0716: parentXPath = "/";
0717:
0718: if (StructureTreeWriter.DOC_TYPE_TYPE.equals(nodeType)
0719: || StructureTreeWriter.DOC_TYPE_TYPE_RELATION
0720: .equals(nodeType)) {
0721: parentType = CacheAdmin.getEnvironment()
0722: .getType(id);
0723: }
0724:
0725: if (StructureTreeWriter.DOC_TYPE_GROUP.equals(nodeType)) {
0726: FxGroupAssignment ga = (FxGroupAssignment) CacheAdmin
0727: .getEnvironment().getAssignment(id);
0728: parentType = ga.getAssignedType();
0729: parentXPath = XPathElement.stripType(ga.getXPath());
0730: }
0731:
0732: property = FxPropertyEdit.createNew("NEWPROPERTY",
0733: new FxString(""), new FxString(""),
0734: FxMultiplicity.MULT_0_1, CacheAdmin
0735: .getEnvironment().getDefaultACL(
0736: ACL.Category.STRUCTURE), null);
0737: initNewPropertyEditing();
0738: } else if ("assignProperty".equals(action)) {
0739: editMode = false;
0740: structureManagement = FxJsfUtils.getRequest()
0741: .getUserTicket().isInRole(
0742: Role.StructureManagement);
0743: if (structureManagement) {
0744: long id = FxJsfUtils.getLongParameter("id");
0745: String nodeType = FxJsfUtils
0746: .getParameter("nodeType");
0747:
0748: parentXPath = "/";
0749:
0750: if (StructureTreeWriter.DOC_TYPE_TYPE
0751: .equals(nodeType)
0752: || StructureTreeWriter.DOC_TYPE_TYPE_RELATION
0753: .equals(nodeType)) {
0754: parentType = CacheAdmin.getEnvironment()
0755: .getType(id);
0756: }
0757:
0758: if (StructureTreeWriter.DOC_TYPE_GROUP
0759: .equals(nodeType)) {
0760: FxGroupAssignment ga = (FxGroupAssignment) CacheAdmin
0761: .getEnvironment().getAssignment(id);
0762: parentType = ga.getAssignedType();
0763: parentXPath = XPathElement.stripType(ga
0764: .getXPath());
0765: }
0766:
0767: long assignmentId = EJBLookup.getAssignmentEngine()
0768: .save(
0769: FxPropertyAssignmentEdit.createNew(
0770: assignment, parentType,
0771: assignment.getAlias(),
0772: parentXPath), false);
0773: StructureTreeControllerBean s = (StructureTreeControllerBean) FxJsfUtils
0774: .getManagedBean("structureTreeControllerBean");
0775: s
0776: .addAction(
0777: StructureTreeControllerBean.ACTION_RELOAD_SELECT_ASSIGNMENT,
0778: assignmentId, "");
0779: }
0780: }
0781: } catch (Throwable t) {
0782: LOG.error("Failed to parse request parameters: "
0783: + t.getMessage(), t);
0784: new FxFacesMsgErr(t).addToContext();
0785: }
0786:
0787: return null;
0788: }
0789:
0790: public void toggleEditMode() {
0791: editMode = !editMode;
0792: }
0793:
0794: public boolean getEditMode() {
0795: return editMode;
0796: }
0797:
0798: public boolean isStructureManagement() {
0799: return structureManagement;
0800: }
0801:
0802: /**
0803: * Initializes variables and does workarounds so editing of an existing property and
0804: * property assignment is possible via the webinterface
0805: */
0806: private void initEditing() {
0807: structureManagement = FxJsfUtils.getRequest().getUserTicket()
0808: .isInRole(Role.StructureManagement);
0809: if (!assignment.isNew())
0810: scriptWrapper = new ScriptListWrapper(assignment.getId(),
0811: false);
0812:
0813: this .defaultMultiplicity = assignment.getDefaultMultiplicity();
0814: setMinMultiplicity(FxMultiplicity.getIntToString(assignment
0815: .getMultiplicity().getMin()));
0816: setMaxMultiplicity(FxMultiplicity.getIntToString(assignment
0817: .getMultiplicity().getMax()));
0818: setPropertyMinMultiplicity(FxMultiplicity
0819: .getIntToString(property.getMultiplicity().getMin()));
0820: setPropertyMaxMultiplicity(FxMultiplicity
0821: .getIntToString(property.getMultiplicity().getMax()));
0822:
0823: optionWrapper = new OptionWrapper(property.getOptions(),
0824: assignment.getOptions(), true);
0825:
0826: try {
0827: //workaround for the system language, which is not loadable:
0828: //set default language as language during the editing process
0829: //if the property assignment didn't become multilang and antoher language was
0830: //assigned, ->restore the system language in the applyChanges method
0831: if (assignment.getDefaultLanguage() == FxLanguage.SYSTEM_ID) {
0832: originalLanguageSystemLanguage = true;
0833: setDefaultLanguage(FxLanguage.DEFAULT);
0834: } else {
0835: FxLanguage language = EJBLookup.getLanguageEngine()
0836: .load(assignment.getDefaultLanguage());
0837: setMultiLang(true);
0838: setDefaultLanguage(language);
0839: }
0840: } catch (Throwable t) {
0841: LOG.error("Failed to initialize the Editing process: "
0842: + t.getMessage(), t);
0843: new FxFacesMsgErr(t).addToContext();
0844: }
0845: }
0846:
0847: /**
0848: * Returns if the FxProperty's Data Type is reference or inlinereference
0849: * in order to enable or disable gui elements.
0850: * @return true if the data type is reference
0851: */
0852: public boolean isPropertyReference() {
0853: if (property.getDataType() == null)
0854: return false;
0855: else
0856: return (property.getDataType().getId() == FxDataType.InlineReference
0857: .getId() || property.getDataType().getId() == FxDataType.Reference
0858: .getId());
0859: }
0860:
0861: /**
0862: * Initializes variables necessarry for creating a new property via the web interface.
0863: * during the creation process, new properties don't have assignments yet.
0864: */
0865: private void initNewPropertyEditing() {
0866: structureManagement = FxJsfUtils.getRequest().getUserTicket()
0867: .isInRole(Role.StructureManagement);
0868: property.setAutoUniquePropertyName(false);
0869: setPropertyMinMultiplicity(FxMultiplicity
0870: .getIntToString(property.getMultiplicity().getMin()));
0871: setPropertyMaxMultiplicity(FxMultiplicity
0872: .getIntToString(property.getMultiplicity().getMax()));
0873: optionWrapper = new OptionWrapper(property.getOptions(), null,
0874: true);
0875: }
0876:
0877: /**
0878: * Returns if the Fxproperty's Data Type is SelectOne or SelectMany
0879: * in order to enable or disable gui elements.
0880: * @return true if the data type is select list
0881: */
0882: public boolean isPropertySelectList() {
0883: if (property.getDataType() == null)
0884: return false;
0885: else
0886: return (property.getDataType().getId() == FxDataType.SelectMany
0887: .getId() || property.getDataType().getId() == FxDataType.SelectOne
0888: .getId());
0889: }
0890:
0891: /**
0892: * Stores a newly created property in DB
0893: */
0894: public void createProperty() {
0895: if (FxJsfUtils.getRequest().getUserTicket().isInRole(
0896: Role.StructureManagement)) {
0897: try {
0898: applyPropertyChanges();
0899: long assignmentId;
0900: if (parentType != null)
0901: assignmentId = EJBLookup.getAssignmentEngine()
0902: .createProperty(parentType.getId(),
0903: property, parentXPath);
0904: else
0905: assignmentId = EJBLookup.getAssignmentEngine()
0906: .createProperty(property, parentXPath);
0907: StructureTreeControllerBean s = (StructureTreeControllerBean) FxJsfUtils
0908: .getManagedBean("structureTreeControllerBean");
0909: s
0910: .addAction(
0911: StructureTreeControllerBean.ACTION_RELOAD_SELECT_ASSIGNMENT,
0912: assignmentId, "");
0913: } catch (Throwable t) {
0914: new FxFacesMsgErr(t).addToContext();
0915: }
0916: } else
0917: new FxFacesMsgErr(new FxApplicationException(
0918: "ex.role.notInRole", "StructureManagement"))
0919: .addToContext();
0920: }
0921:
0922: /**
0923: * Forward property and property assignment changes to the DB
0924: */
0925: public void saveChanges() {
0926: if (FxJsfUtils.getRequest().getUserTicket().isInRole(
0927: Role.ScriptManagement))
0928: try {
0929: if (!property.isNew())
0930: saveScriptChanges();
0931: } catch (Throwable t) {
0932: new FxFacesMsgErr(t).addToContext();
0933: }
0934: else
0935: new FxFacesMsgInfo(
0936: "info.structureEditor.notInRole.scriptManagement")
0937: .addToContext();
0938:
0939: if (FxJsfUtils.getRequest().getUserTicket().isInRole(
0940: Role.StructureManagement)) {
0941: try {
0942: applyPropertyChanges();
0943: EJBLookup.getAssignmentEngine().save(property);
0944: savePropertyAssignmentChanges();
0945: StructureTreeControllerBean s = (StructureTreeControllerBean) FxJsfUtils
0946: .getManagedBean("structureTreeControllerBean");
0947: s
0948: .addAction(
0949: StructureTreeControllerBean.ACTION_RENAME_SELECT_ASSIGNMENT,
0950: assignment.getId(), assignment
0951: .getDisplayName());
0952: } catch (Throwable t) {
0953: new FxFacesMsgErr(t).addToContext();
0954: }
0955: } else
0956: new FxFacesMsgInfo(
0957: "info.structureEditor.notInRole.structureManagement")
0958: .addToContext();
0959: }
0960:
0961: /**
0962: * Apply all changes to the property assignment which are still cached in
0963: * the view (property options, multiplicity, label, scripts) and forward them to DB
0964: *
0965: * @throws FxApplicationException if the label is invalid
0966: */
0967: private void savePropertyAssignmentChanges()
0968: throws FxApplicationException {
0969: if (assignment.getLabel().getIsEmpty()) {
0970: throw new FxApplicationException(
0971: "ex.structureEditor.noLabel");
0972: }
0973: int min = FxMultiplicity.getStringToInt(minMultiplicity);
0974: int max = FxMultiplicity.getStringToInt(maxMultiplicity);
0975:
0976: //delete current options
0977: while (!assignment.getOptions().isEmpty()) {
0978: String key = assignment.getOptions().get(0).getKey();
0979: assignment.clearOption(key);
0980: }
0981: //add edited options
0982: List<FxStructureOption> newAssignmentOptions = optionWrapper
0983: .asFxStructureOptionList(optionWrapper
0984: .getAssignmentOptions());
0985: for (FxStructureOption o : newAssignmentOptions) {
0986: assignment.setOption(o.getKey(), o.getValue());
0987: }
0988:
0989: //in any case restore the system language for systeminternal properties
0990: if (isSystemInternal() && originalLanguageSystemLanguage) {
0991: assignment.setDefaultLanguage(FxLanguage.SYSTEM_ID);
0992: }
0993:
0994: if (!isSystemInternal()
0995: || FxJsfUtils.getRequest().getUserTicket().isInRole(
0996: Role.GlobalSupervisor)) {
0997: if (getProperty().mayOverrideBaseMultiplicity()) {
0998: FxJsfUtils.checkMultiplicity(min, max);
0999: assignment
1000: .setMultiplicity(new FxMultiplicity(min, max));
1001: }
1002: assignment.setDefaultMultiplicity(this .defaultMultiplicity);
1003:
1004: if (originalLanguageSystemLanguage && !isMultiLang()) {
1005: assignment.setDefaultLanguage(FxLanguage.SYSTEM_ID);
1006: } else
1007: assignment.setDefaultLanguage(defaultLanguage.getId());
1008: EJBLookup.getAssignmentEngine().save(assignment, false);
1009: }
1010: }
1011:
1012: /**
1013: * Apply all changes to the property which are still cached in
1014: * the view (property options, multiplicity, label)
1015: *
1016: * @throws FxApplicationException if the label is invalid
1017: */
1018: private void applyPropertyChanges() throws FxApplicationException {
1019: if (property.getLabel().getIsEmpty()) {
1020: throw new FxApplicationException(
1021: "ex.structureEditor.noLabel");
1022: }
1023:
1024: int min = FxMultiplicity
1025: .getStringToInt(propertyMinMultiplicity);
1026: int max = FxMultiplicity
1027: .getStringToInt(propertyMaxMultiplicity);
1028:
1029: FxJsfUtils.checkMultiplicity(min, max);
1030:
1031: //delete current options
1032: while (!property.getOptions().isEmpty()) {
1033: String key = property.getOptions().get(0).getKey();
1034: property.clearOption(key);
1035: }
1036: //add edited options
1037: List<FxStructureOption> newGroupOptions = optionWrapper
1038: .asFxStructureOptionList(optionWrapper
1039: .getStructureOptions());
1040: for (FxStructureOption o : newGroupOptions) {
1041: property.setOption(o.getKey(), o.isOverrideable(), o
1042: .getValue());
1043: }
1044:
1045: if (!isSystemInternal()
1046: || FxJsfUtils.getRequest().getUserTicket().isInRole(
1047: Role.GlobalSupervisor)) {
1048: property.setMultiplicity(new FxMultiplicity(min, max));
1049: }
1050: }
1051:
1052: /**
1053: * Show the PropertyAssignmentEditor
1054: *
1055: * @return the next page
1056: */
1057: public String showPropertyAssignmentEditor() {
1058: return "propertyAssignmentEditor";
1059: }
1060:
1061: /**
1062: * Show the PropertyEditor
1063: *
1064: * @return the next page
1065: */
1066: public String showPropertyEditor() {
1067: return "propertyEditor";
1068: }
1069:
1070: /**
1071: * Show the OptionEditor
1072: *
1073: * @return the next page
1074: */
1075: public String showPropertyOptionEditor() {
1076: return "propertyOptionEditor";
1077: }
1078:
1079: /***************** script editor tab begin ************************/
1080:
1081: public String showAssignmentScriptEditor() {
1082: return "assignmentScriptEditor";
1083: }
1084:
1085: /**
1086: * called from the script editor; to open an instance where the script is assigned to
1087: *
1088: * @return type editor page
1089: */
1090: public String gotoAssignmentScriptEditor() {
1091: editMode = false;
1092: long propId = FxJsfUtils.getLongParameter("oid", -1);
1093: setPropertyId(propId);
1094: FxPropertyAssignmentEdit assignment = ((FxPropertyAssignment) CacheAdmin
1095: .getEnvironment().getAssignment(propId)).asEditable();
1096: setAssignment(assignment);
1097: setProperty(assignment.getPropertyEdit());
1098: initEditing();
1099: return showAssignmentScriptEditor();
1100: }
1101:
1102: public ScriptListWrapper getScriptWrapper() {
1103: return scriptWrapper;
1104: }
1105:
1106: public int getScriptCount() {
1107: return scriptWrapper == null ? 0 : scriptWrapper
1108: .getScriptList().size();
1109: }
1110:
1111: public int getScriptListFiler() {
1112: return scriptListFiler;
1113: }
1114:
1115: public void setScriptListFiler(int scriptListFiler) {
1116: this .scriptListFiler = scriptListFiler;
1117: }
1118:
1119: public void removeScript() {
1120: scriptWrapper.remove(scriptListFiler);
1121: }
1122:
1123: public FxScriptInfo getSelectedScriptInfo() {
1124: return selectedScriptInfo;
1125: }
1126:
1127: public void setSelectedScriptInfo(FxScriptInfo selectedScriptInfo) {
1128: this .selectedScriptInfo = selectedScriptInfo;
1129: }
1130:
1131: public long getSelectedScriptEventId() {
1132: if (selectedScriptInfo != null)
1133: return selectedScriptInfo.getEvent().getId();
1134: else
1135: return -1;
1136: //return selectedScriptEventId;
1137: }
1138:
1139: public void setSelectedScriptEventId(long selectedScriptEventId) {
1140: this .selectedScriptEventId = selectedScriptEventId;
1141: }
1142:
1143: public boolean isSelectedDerivedUsage() {
1144: return selectedDerivedUsage;
1145: }
1146:
1147: public void setSelectedDerivedUsage(boolean selectedDerivedUsage) {
1148: this .selectedDerivedUsage = selectedDerivedUsage;
1149: }
1150:
1151: public boolean isSelectedActive() {
1152: return selectedActive;
1153: }
1154:
1155: public void setSelectedActive(boolean selectedActive) {
1156: this .selectedActive = selectedActive;
1157: }
1158:
1159: public void addScript() {
1160: try {
1161: scriptWrapper.add(selectedScriptInfo.getId(),
1162: selectedScriptEventId, selectedDerivedUsage,
1163: selectedActive);
1164: this .selectedScriptInfo = CacheAdmin
1165: .getFilteredEnvironment().getScripts().get(0);
1166: this .selectedScriptInfo.getEvent().getId();
1167: } catch (Throwable t) {
1168: //TODO: print error message, a4j tags do not support faces message erros
1169: //new FxFacesMsgErr(t).addToContext();
1170: }
1171: }
1172:
1173: public Map<Long, String> getAssignmentNameForId() {
1174: return new HashMap<Long, String>() {
1175: public String get(Object key) {
1176: return CacheAdmin.getFilteredEnvironment()
1177: .getAssignment((Long) key).getXPath();
1178: }
1179: };
1180: }
1181:
1182: /**
1183: * Saves script assignment changes to DB.
1184: *
1185: * @throws com.flexive.shared.exceptions.FxApplicationException on errors
1186: */
1187: private void saveScriptChanges() throws FxApplicationException {
1188: for (ScriptListWrapper.ScriptListEntry e : scriptWrapper
1189: .getDelta(assignment.getId(), false)) {
1190: if (e.getId() == ScriptListWrapper.ID_SCRIPT_ADDED)
1191: EJBLookup.getScriptingEngine()
1192: .createAssignmentScriptMapping(
1193: e.getScriptEvent(),
1194: e.getScriptInfo().getId(),
1195: assignment.getId(), e.isActive(),
1196: e.isDerivedUsage());
1197: else if (e.getId() == ScriptListWrapper.ID_SCRIPT_REMOVED)
1198: EJBLookup.getScriptingEngine()
1199: .removeAssignmentScriptMappingForEvent(
1200: e.getScriptInfo().getId(),
1201: assignment.getId(), e.getScriptEvent());
1202: else if (e.getId() == ScriptListWrapper.ID_SCRIPT_UPDATED)
1203: EJBLookup.getScriptingEngine()
1204: .updateAssignmentScriptMappingForEvent(
1205: e.getScriptInfo().getId(),
1206: assignment.getId(), e.getScriptEvent(),
1207: e.isActive(), e.isDerivedUsage());
1208: }
1209: }
1210:
1211: /****script editor tab end*********/
1212:
1213: }
|