0001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012: // POSSIBILITY OF SUCH DAMAGE.
0013: //
0014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015: package com.metaboss.sdlctools.models.modelassistant.metabossmodel.domainsupport;
0016:
0017: import java.util.ArrayList;
0018: import java.util.Collection;
0019: import java.util.HashSet;
0020: import java.util.Iterator;
0021: import java.util.List;
0022: import java.util.Set;
0023:
0024: import javax.jmi.reflect.ConstraintViolationException;
0025: import javax.jmi.reflect.RefObject;
0026:
0027: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
0028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
0029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
0030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
0031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
0032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
0033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
0034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
0035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum;
0037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
0038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
0039: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
0040: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
0041: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
0042: import com.metaboss.util.StringUtils;
0043:
0044: /** This class containse helper methods dealing with the Domain Support Servicemodule model element */
0045: class TargetCreateEntityOperationHelper {
0046: private ModelAssistantImpl mModelAssistantImpl;
0047:
0048: TargetCreateEntityOperationHelper(
0049: ModelAssistantImpl pModelAssistantImpl) {
0050: mModelAssistantImpl = pModelAssistantImpl;
0051:
0052: // Add entity lifecycle listener
0053: mModelAssistantImpl.addLifecycleListener(Entity.class,
0054: new ModelAssistantImpl.ModelElementLifecycleListener() {
0055: public void onElementJustCreated(
0056: RefObject pModelElementJustCreated) {
0057: Entity lEntity = (Entity) pModelElementJustCreated;
0058: String lEntityName = lEntity.getName();
0059: if (lEntityName == null)
0060: return; // Domain does not have a name
0061: Domain lDomain = lEntity.getDomain();
0062: if (lDomain == null)
0063: return; // Entity is not associated with domain
0064: String lDomainName = lDomain.getName();
0065: if (lDomainName == null)
0066: return; // Domain does not have a name
0067: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0068: .getSystem();
0069: if (lSystem == null)
0070: return; // Domain is not associated with system
0071: Servicemodule lServicemodule = lSystem
0072: .findServicemodule(StylesheetImpl
0073: .getDomainSupportServicemoduleName(lDomainName));
0074: if (lServicemodule == null)
0075: return; // There is no support servicemodule yet
0076: Service lDomainSupportService = lServicemodule
0077: .findService(StylesheetImpl
0078: .getDataManagementServiceName(lDomainName));
0079: if (lDomainSupportService == null)
0080: return; // There is no domain support service yet
0081: // Create or remove associated element as per condition
0082: if (!lEntity.isAbstract())
0083: ensurePresent(lDomainSupportService,
0084: lEntity, lEntityName);
0085: else
0086: ensureAbsent(lDomainSupportService,
0087: lEntityName);
0088: }
0089:
0090: public void onElementBeingDeleted(
0091: RefObject pModelElementBeingDeleted) {
0092: Entity lEntity = (Entity) pModelElementBeingDeleted;
0093: String lEntityName = lEntity.getName();
0094: if (lEntityName == null)
0095: return; // Domain does not have a name
0096: Domain lDomain = lEntity.getDomain();
0097: if (lDomain == null)
0098: return; // Entity is not associated with domain
0099: String lDomainName = lDomain.getName();
0100: if (lDomainName == null)
0101: return; // Domain does not have a name
0102: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0103: .getSystem();
0104: if (lSystem == null)
0105: return; // Domain is not associated with system
0106: Servicemodule lServicemodule = lSystem
0107: .findServicemodule(StylesheetImpl
0108: .getDomainSupportServicemoduleName(lDomainName));
0109: if (lServicemodule == null)
0110: return; // There is no support servicemodule yet
0111: Service lDomainSupportService = lServicemodule
0112: .findService(StylesheetImpl
0113: .getDataManagementServiceName(lDomainName));
0114: if (lDomainSupportService == null)
0115: return; // There is no domain support service yet
0116: // Remove associated element always
0117: ensureAbsent(lDomainSupportService, lEntityName);
0118: }
0119: });
0120: // Add entity Name attribute change listener
0121: mModelAssistantImpl
0122: .addAttributeChangeListener(
0123: Entity.class,
0124: "Name",
0125: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0126: public void onAttributeBeingUpdated(
0127: RefObject pModelElementBeingUpdated,
0128: String pAttributeName,
0129: Object pOldValue, Object pNewValue) {
0130: Entity lEntity = (Entity) pModelElementBeingUpdated;
0131: Domain lDomain = lEntity.getDomain();
0132: if (lDomain == null)
0133: return; // Entity is not associated with domain
0134: String lDomainName = lDomain.getName();
0135: if (lDomainName == null)
0136: return; // Domain does not have a name
0137: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0138: .getSystem();
0139: if (lSystem == null)
0140: return; // Domain is not associated with system
0141: Servicemodule lServicemodule = lSystem
0142: .findServicemodule(StylesheetImpl
0143: .getDomainSupportServicemoduleName(lDomainName));
0144: if (lServicemodule == null)
0145: return; // There is no support servicemodule yet
0146: Service lDomainSupportService = lServicemodule
0147: .findService(StylesheetImpl
0148: .getDataManagementServiceName(lDomainName));
0149: if (lDomainSupportService == null)
0150: return; // There is no domain support service yet
0151: if (pNewValue == null) {
0152: // Only old value is known - ensure that the element is deleted
0153: ensureAbsent(lDomainSupportService,
0154: (String) pOldValue);
0155: } else {
0156: // New value is known - analyse the criteria and deal with the element accordingly
0157: if (!lEntity.isAbstract()) {
0158: // The element must be present - rename or create
0159: if (pOldValue != null)
0160: ensureRenamedPresent(
0161: lDomainSupportService,
0162: lEntity,
0163: (String) pOldValue,
0164: (String) pNewValue);
0165: else
0166: ensurePresent(
0167: lDomainSupportService,
0168: lEntity,
0169: (String) pNewValue);
0170: } else {
0171: // The element must be absent - delete
0172: ensureAbsent(
0173: lDomainSupportService,
0174: (String) pNewValue);
0175: if (pOldValue != null)
0176: ensureAbsent(
0177: lDomainSupportService,
0178: (String) pOldValue);
0179: }
0180: }
0181: }
0182: });
0183: // Add entity isAbstract attribute change listener
0184: mModelAssistantImpl
0185: .addAttributeChangeListener(
0186: Entity.class,
0187: "isAbstract",
0188: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0189: public void onAttributeBeingUpdated(
0190: RefObject pModelElementBeingUpdated,
0191: String pAttributeName,
0192: Object pOldValue, Object pNewValue) {
0193: Entity lEntity = (Entity) pModelElementBeingUpdated;
0194: String lEntityName = lEntity.getName();
0195: if (lEntityName == null)
0196: return; // Entity does not have a name
0197: Domain lDomain = lEntity.getDomain();
0198: if (lDomain == null)
0199: return; // Entity is not associated with domain
0200: String lDomainName = lDomain.getName();
0201: if (lDomainName == null)
0202: return; // Domain does not have a name
0203: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0204: .getSystem();
0205: if (lSystem == null)
0206: return; // Domain is not associated with system
0207: Servicemodule lServicemodule = lSystem
0208: .findServicemodule(StylesheetImpl
0209: .getDomainSupportServicemoduleName(lDomainName));
0210: if (lServicemodule == null)
0211: return; // There is no support servicemodule yet
0212: Service lDomainSupportService = lServicemodule
0213: .findService(StylesheetImpl
0214: .getDataManagementServiceName(lDomainName));
0215: if (lDomainSupportService == null)
0216: return; // There is no domain support service yet
0217: // Analyse the criteria and deal with the element accordingly
0218: if (Boolean.FALSE.equals(pNewValue))
0219: ensurePresent(
0220: lDomainSupportService,
0221: lEntity, lEntityName);
0222: else
0223: ensureAbsent(lDomainSupportService,
0224: lEntityName);
0225: }
0226: });
0227: // Add entity primaryKeyElements reference change listener
0228: mModelAssistantImpl
0229: .addReferenceChangeListener(
0230: Entity.class,
0231: "primaryKeyElements",
0232: new ModelAssistantImpl.ModelElementReferenceChangeListener() {
0233: public void onReferenceBeingUpdated(
0234: RefObject pModelElementBeingUpdated,
0235: String pReferenceName,
0236: RefObject pReferencedModelElementToRemove,
0237: RefObject pReferencedModelElementToAdd) {
0238: Entity lEntity = (Entity) pModelElementBeingUpdated;
0239: String lEntityName = lEntity.getName();
0240: if (lEntityName == null)
0241: return; // Entity does not have a name
0242: Domain lDomain = lEntity.getDomain();
0243: if (lDomain == null)
0244: return; // Entity is not associated with domain
0245: String lDomainName = lDomain.getName();
0246: if (lDomainName == null)
0247: return; // Domain does not have a name
0248: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0249: .getSystem();
0250: if (lSystem == null)
0251: return; // Domain is not associated with system
0252: Servicemodule lServicemodule = lSystem
0253: .findServicemodule(StylesheetImpl
0254: .getDomainSupportServicemoduleName(lDomainName));
0255: if (lServicemodule == null)
0256: return; // There is no support servicemodule yet
0257: Service lDomainSupportService = lServicemodule
0258: .findService(StylesheetImpl
0259: .getDataManagementServiceName(lDomainName));
0260: if (lDomainSupportService == null)
0261: return; // There is no domain support service yet
0262: // Analyse the criteria and deal with the element accordingly
0263: if (pReferencedModelElementToAdd != null)
0264: duplicateCreateFailedMessage_EnsurePresent(
0265: lDomainSupportService,
0266: lEntityName); // Primary key element is being added
0267: else if (pReferencedModelElementToRemove != null) {
0268: List lAllPrimaryKeyElements = new ArrayList();
0269: lAllPrimaryKeyElements
0270: .addAll(lEntity
0271: .getPrimaryKeyElements());
0272: lAllPrimaryKeyElements
0273: .remove(pReferencedModelElementToRemove);
0274: if (!lAllPrimaryKeyElements
0275: .isEmpty())
0276: duplicateCreateFailedMessage_EnsurePresent(
0277: lDomainSupportService,
0278: lEntityName); // Primary key will stay
0279: else
0280: duplicateCreateFailedMessage_EnsureAbsent(
0281: lDomainSupportService,
0282: lEntityName); // Primary key will disappear
0283: }
0284: }
0285: });
0286:
0287: }
0288:
0289: private static String sOperationConstraintTextBase = "A Data Management Service must have Create Entity operation for every non-abstract Entity in the corresponding Domain.";
0290: private static String sProposedInstanceDetailsInputFieldConstraintTextBase = "A Create Entity Data Management Operation must have well formed Proposed Instance Details input parameter carrying proposed details of the created Entity.";
0291: private static String sCreatedInstanceDetailsOutputFieldConstraintTextBase = "A Create Entity Data Management Operation must have well formed Created Instance Details output parameter carrying actual details of the created Entity.";
0292: private static String sDuplicateCreateFailedOutputMessageConstraintTextBase = "A Create Entity Data Management Operation must have well formed Duplicate Create Instance Failed output message if entity has natural primary key.";
0293: private static String sMandatoryReferenceCanNotBeEmptyOutputMessageConstraintTextBase = "A Create Entity Data Management Operation must have well formed Mandatory Reference Can Not Be Empty output message, one for each mandatory reference.";
0294: private static String sEntityNotFoundErrorOutputMessageConstraintTextBase = "A Create Entity Data Management Operation must have well formed Entity Not Found output message, one for each mandatory reference.";
0295: private static final String sOperationInputConstraintTextBase = "A Create Entity Data Management Operation must have well formed Input Constraints performing sanity check on the input data.";
0296:
0297: // This helper verifies constraints
0298: void verifyConstraints(Collection pViolations,
0299: Service pDataManagementService, Entity pEntity,
0300: Collection pUnclaimedOperations) {
0301: String lEntityName = pEntity.getName();
0302: if (lEntityName == null)
0303: return;
0304: // Work on Operation
0305: String lOperationName = suggestOperationName(lEntityName);
0306: Operation lOperation = pDataManagementService
0307: .findOperation(lOperationName);
0308: if (lOperation == null) {
0309: if (!pEntity.isAbstract())
0310: pViolations.add(new ConstraintViolationException(
0311: pDataManagementService, pDataManagementService
0312: .refMetaObject(),
0313: sOperationConstraintTextBase + " The '"
0314: + lOperationName
0315: + "' Operation not found."));
0316: return;
0317: }
0318: pUnclaimedOperations.remove(lOperation); // Claim the operation
0319: if (pEntity.isAbstract()) {
0320: pViolations.add(new ConstraintViolationException(
0321: pDataManagementService, pDataManagementService
0322: .refMetaObject(),
0323: sOperationConstraintTextBase + " The '"
0324: + lOperationName
0325: + "' Operation unexpected."));
0326: return;
0327: }
0328: // Validate operation details
0329: if (!TransactionPolicyEnum.REQUIRED.equals(lOperation
0330: .getTransactionPolicy()))
0331: pViolations.add(new ConstraintViolationException(
0332: lOperation, lOperation.refMetaObject(),
0333: "Create Entity Operation must have transaction policy '"
0334: + TransactionPolicyEnum.REQUIRED.toString()
0335: + "'. The '"
0336: + lOperation.getTransactionPolicy()
0337: + "' Transaction policy is unexpected."));
0338: if (lOperation.isQuery())
0339: pViolations
0340: .add(new ConstraintViolationException(lOperation,
0341: lOperation.refMetaObject(),
0342: "Create Entity Operation must have the isQuery attribute set to false."));
0343:
0344: Structure lEntityDetailsStructure = pDataManagementService
0345: .getServicemodule() != null ? pDataManagementService
0346: .getServicemodule()
0347: .findStructure(
0348: StylesheetImpl
0349: .getEntityDetailsStructureName(lEntityName))
0350: : null;
0351: // Input Fields - only verify that the ones that we need exist. The extra ones are allowed
0352: {
0353: String lOperationInputFieldName = suggestProposedDetailsInputParameterName(lEntityName);
0354: OperationInputField lInputField = lOperation
0355: .findInputField(lOperationInputFieldName);
0356: if (lInputField != null) {
0357: if (lEntityDetailsStructure != null
0358: && lEntityDetailsStructure.equals(lInputField
0359: .getStructureType()) == false)
0360: pViolations.add(new ConstraintViolationException(
0361: lInputField, lInputField.refMetaObject(),
0362: sProposedInstanceDetailsInputFieldConstraintTextBase
0363: + " The '"
0364: + lOperationInputFieldName
0365: + "' input field has wrong type."));
0366: if (lInputField.isArray())
0367: pViolations
0368: .add(new ConstraintViolationException(
0369: lInputField,
0370: lInputField.refMetaObject(),
0371: sProposedInstanceDetailsInputFieldConstraintTextBase
0372: + " The '"
0373: + lOperationInputFieldName
0374: + "' input field is an array, which is wrong."));
0375: } else
0376: pViolations.add(new ConstraintViolationException(
0377: lOperation, lOperation.refMetaObject(),
0378: sProposedInstanceDetailsInputFieldConstraintTextBase
0379: + " The '" + lOperationInputFieldName
0380: + "' input field is missing."));
0381: }
0382: // Input constraints
0383: {
0384: String lOperationInputFieldName = suggestProposedDetailsInputParameterName(lEntityName);
0385: // Work on the field presence constraint.
0386: {
0387: String lConstraintName = lOperationInputFieldName
0388: + "FieldPresenceConstraint";
0389: ModelElementConstraint lModelElementConstraint = lOperation
0390: .findInputConstraint(lConstraintName);
0391: if (lModelElementConstraint == null)
0392: pViolations
0393: .add(new ConstraintViolationException(
0394: lOperation,
0395: lOperation.refMetaObject(),
0396: sOperationInputConstraintTextBase
0397: + " The '"
0398: + lConstraintName
0399: + "' Input Constraint is missing."));
0400: }
0401: // Work on the mandatory fields presence constraints.
0402: for (Iterator lAttributesIterator = pEntity
0403: .getCombinedAttributes().iterator(); lAttributesIterator
0404: .hasNext();) {
0405: Attribute lAttribute = (Attribute) lAttributesIterator
0406: .next();
0407: String lAttributeFieldName = StylesheetImpl
0408: .getEntityAttributeStructureFieldName(lAttribute
0409: .getName());
0410: String lConstraintName = lOperationInputFieldName
0411: + lAttributeFieldName
0412: + "FieldPresenceConstraint";
0413: ModelElementConstraint lModelElementConstraint = lOperation
0414: .findInputConstraint(lConstraintName);
0415: if (AttributeStereotypeEnum.MANDATORY.equals(lAttribute
0416: .getStereotype())) {
0417: if (lModelElementConstraint == null)
0418: pViolations
0419: .add(new ConstraintViolationException(
0420: lOperation,
0421: lOperation.refMetaObject(),
0422: sOperationInputConstraintTextBase
0423: + " The '"
0424: + lConstraintName
0425: + "' Input Constraint is missing."));
0426: } else {
0427: if (lModelElementConstraint != null)
0428: pViolations
0429: .add(new ConstraintViolationException(
0430: lOperation,
0431: lOperation.refMetaObject(),
0432: sOperationInputConstraintTextBase
0433: + " The '"
0434: + lConstraintName
0435: + "' Input Constraint is not required."));
0436: }
0437: }
0438: // Work on mandatory references presence constraints
0439: for (Iterator lReferencesIterator = pEntity
0440: .getCombinedReferences().iterator(); lReferencesIterator
0441: .hasNext();) {
0442: AssociationRole lReference = (AssociationRole) lReferencesIterator
0443: .next();
0444: String lRefefrenceFieldName = StylesheetImpl
0445: .getEntityReferenceStructureFieldName(lReference
0446: .getName());
0447: String lConstraintName = lOperationInputFieldName
0448: + lRefefrenceFieldName
0449: + "FieldPresenceConstraint";
0450: ModelElementConstraint lModelElementConstraint = lOperation
0451: .findInputConstraint(lConstraintName);
0452: if (lReference.isSingular() && lReference.isMandatory()) {
0453: if (lModelElementConstraint == null)
0454: pViolations
0455: .add(new ConstraintViolationException(
0456: lOperation,
0457: lOperation.refMetaObject(),
0458: sOperationInputConstraintTextBase
0459: + " The '"
0460: + lConstraintName
0461: + "' Input Constraint is missing."));
0462: } else {
0463: if (lModelElementConstraint != null)
0464: pViolations
0465: .add(new ConstraintViolationException(
0466: lOperation,
0467: lOperation.refMetaObject(),
0468: sOperationInputConstraintTextBase
0469: + " The '"
0470: + lConstraintName
0471: + "' Input Constraint is not required."));
0472: }
0473: }
0474: }
0475: // Output Fields - only verify that the ones that we need exist. The extra ones are allowed
0476: {
0477: String lOperationOutputFieldName = suggestCreatedDetailsReturnParameterName(lEntityName);
0478: OperationOutputField lOutputField = lOperation
0479: .findOutputField(lOperationOutputFieldName);
0480: if (lOutputField != null) {
0481: if (lEntityDetailsStructure != null
0482: && lEntityDetailsStructure.equals(lOutputField
0483: .getStructureType()) == false)
0484: pViolations
0485: .add(new ConstraintViolationException(
0486: lOutputField,
0487: lOutputField.refMetaObject(),
0488: sCreatedInstanceDetailsOutputFieldConstraintTextBase
0489: + " The '"
0490: + lOperationOutputFieldName
0491: + "' output field has wrong type."));
0492: if (lOutputField.isArray())
0493: pViolations
0494: .add(new ConstraintViolationException(
0495: lOutputField,
0496: lOutputField.refMetaObject(),
0497: sCreatedInstanceDetailsOutputFieldConstraintTextBase
0498: + " The '"
0499: + lOperationOutputFieldName
0500: + "' output field is an array, which is wrong."));
0501: } else
0502: pViolations.add(new ConstraintViolationException(
0503: lOperation, lOperation.refMetaObject(),
0504: sCreatedInstanceDetailsOutputFieldConstraintTextBase
0505: + " The '" + lOperationOutputFieldName
0506: + "' output field is missing."));
0507: }
0508: // Output Messages - only verify that the ones that we need exist. The extra ones are allowed
0509: {
0510: // If entity has primary key - it is possible to get creation error. Message has to be declared
0511: if (!pEntity.getPrimaryKeyElements().isEmpty()) {
0512: String lOperationOutputMessageName = suggestDuplicateCreateFailedReturnMessageName(lEntityName);
0513: OperationOutputMessage lOutputMessage = lOperation
0514: .findOutputMessage(lOperationOutputMessageName);
0515: if (lOutputMessage != null) {
0516: Message lDuplicateCreateFailedMessage = pDataManagementService
0517: .getServicemodule() != null ? pDataManagementService
0518: .getServicemodule()
0519: .findMessage(
0520: StylesheetImpl
0521: .getDuplicateCreateFailedMessageName(lEntityName))
0522: : null;
0523: if (lDuplicateCreateFailedMessage != null
0524: && lDuplicateCreateFailedMessage
0525: .equals(lOutputMessage
0526: .getMessageType()) == false)
0527: pViolations
0528: .add(new ConstraintViolationException(
0529: lOutputMessage,
0530: lOutputMessage.refMetaObject(),
0531: sDuplicateCreateFailedOutputMessageConstraintTextBase
0532: + " The '"
0533: + lOperationOutputMessageName
0534: + "' output message has wrong type."));
0535: if (lOutputMessage.isArray())
0536: pViolations
0537: .add(new ConstraintViolationException(
0538: lOutputMessage,
0539: lOutputMessage.refMetaObject(),
0540: sDuplicateCreateFailedOutputMessageConstraintTextBase
0541: + " The '"
0542: + lOperationOutputMessageName
0543: + "' output message is an array, which is wrong."));
0544: } else
0545: pViolations.add(new ConstraintViolationException(
0546: lOperation, lOperation.refMetaObject(),
0547: sDuplicateCreateFailedOutputMessageConstraintTextBase
0548: + " The '"
0549: + lOperationOutputMessageName
0550: + "' output message is missing."));
0551: }
0552:
0553: // We may have entity instances not found for the entities which may be specified during creation
0554: Set lEntitiesWhichMayBeNotFoundWhenCreatingInstance = new HashSet();
0555: Util
0556: .collectEntitiesWhichMayBeNotFoundWhenUpdatingOrCreatingInstance(
0557: pEntity,
0558: lEntitiesWhichMayBeNotFoundWhenCreatingInstance);
0559: for (Iterator lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenCreatingInstance
0560: .iterator(); lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator
0561: .hasNext();) {
0562: Entity lEntityElement = (Entity) lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator
0563: .next();
0564: String lEntityElementName = lEntityElement.getName();
0565: if (lEntityElementName == null)
0566: continue;
0567: String lOperationOutputMessageName = StylesheetImpl
0568: .getEntityNotFoundOperationOutputMessageName(lEntityElementName);
0569: OperationOutputMessage lOutputMessage = lOperation
0570: .findOutputMessage(lOperationOutputMessageName);
0571: if (lOutputMessage != null) {
0572: Message lEntityInstanceNotFoundMessage = pDataManagementService
0573: .getServicemodule() != null ? pDataManagementService
0574: .getServicemodule()
0575: .findMessage(
0576: StylesheetImpl
0577: .getEntityInstanceNotFoundMessageName(lEntityElementName))
0578: : null;
0579: if (lEntityInstanceNotFoundMessage != null
0580: && lEntityInstanceNotFoundMessage
0581: .equals(lOutputMessage
0582: .getMessageType()) == false)
0583: pViolations
0584: .add(new ConstraintViolationException(
0585: lOutputMessage,
0586: lOutputMessage.refMetaObject(),
0587: sEntityNotFoundErrorOutputMessageConstraintTextBase
0588: + " The '"
0589: + lOperationOutputMessageName
0590: + "' output message has wrong type."));
0591: if (lOutputMessage.isArray())
0592: pViolations
0593: .add(new ConstraintViolationException(
0594: lOutputMessage,
0595: lOutputMessage.refMetaObject(),
0596: sEntityNotFoundErrorOutputMessageConstraintTextBase
0597: + " The '"
0598: + lOperationOutputMessageName
0599: + "' output message is an array, which is wrong."));
0600: } else
0601: pViolations.add(new ConstraintViolationException(
0602: lOperation, lOperation.refMetaObject(),
0603: sEntityNotFoundErrorOutputMessageConstraintTextBase
0604: + " The '"
0605: + lOperationOutputMessageName
0606: + "' output message is missing."));
0607: }
0608: }
0609: }
0610:
0611: // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
0612: void rectifyModel(Service pDataManagementService, Entity pEntity,
0613: Collection pUnclaimedOperations) {
0614: // Check if we have an operation and than just call ensurePresent
0615: String lEntityName = pEntity.getName();
0616: String lOperationName = suggestOperationName(lEntityName);
0617: Operation lOperation = pDataManagementService
0618: .findOperation(lOperationName);
0619: if (lOperation != null)
0620: pUnclaimedOperations.remove(lOperation); // Claim the operation
0621: if (!pEntity.isAbstract())
0622: ensurePresent(pDataManagementService, pEntity, lEntityName);
0623: else
0624: ensureAbsent(pDataManagementService, lEntityName);
0625: }
0626:
0627: // This helper renames and ensures that the element is present
0628: void ensureRenamedPresent(Service pDataManagementService,
0629: Entity pEntity, String pOldEntityName, String pNewEntityName) {
0630: // Note that this method only deals with renaming and than calls the ensure present method
0631: String lOldOperationName = suggestOperationName(pOldEntityName);
0632: Operation lOldOperation = pDataManagementService
0633: .findOperation(lOldOperationName);
0634: String lNewOperationName = suggestOperationName(pNewEntityName);
0635: Operation lNewOperation = pDataManagementService
0636: .findOperation(lNewOperationName);
0637: // Be relaxed here - allow for all sorts of mishaps
0638: if (lOldOperation != null) {
0639: if (lNewOperation != null) {
0640: // New and old structures are present - just delete the old one
0641: lOldOperation.refDelete();
0642: } else {
0643: // Old structure is present - new one is not - rename
0644: lOldOperation.setName(lNewOperationName);
0645: }
0646: }
0647: // Call the ensure present bit
0648: ensurePresent(pDataManagementService, pEntity, pNewEntityName);
0649: }
0650:
0651: // This helper makes sure that the version id attribute is present in the details structure
0652: void ensurePresent(Service pDataManagementService, Entity pEntity,
0653: String pEntityName) {
0654: Structure lEntityDetailsStructure = pDataManagementService
0655: .getServicemodule() != null ? pDataManagementService
0656: .getServicemodule()
0657: .findStructure(
0658: StylesheetImpl
0659: .getEntityDetailsStructureName(pEntityName))
0660: : null;
0661: // Work on the servicemodule
0662: String lOperationName = suggestOperationName(pEntityName);
0663: Operation lOperation = pDataManagementService
0664: .findOperation(lOperationName);
0665: if (lOperation == null) {
0666: lOperation = mModelAssistantImpl.mOperationClass
0667: .createOperation();
0668: lOperation.setService(pDataManagementService);
0669: lOperation.setName(lOperationName);
0670: }
0671: lOperation
0672: .setDescription(suggestOperationDescription(pEntityName));
0673: lOperation.setTransactionPolicy(TransactionPolicyEnum.REQUIRED);
0674: lOperation.setQuery(false);
0675: // Input Fields
0676: {
0677: Collection lOperationInputFields = lOperation
0678: .getInputFields();
0679: List lUnprocessedInputFields = new ArrayList();
0680: lUnprocessedInputFields.addAll(lOperationInputFields);
0681: {
0682: String lOperationInputFieldName = suggestProposedDetailsInputParameterName(pEntityName);
0683: OperationInputField lInputField = lOperation
0684: .findInputField(lOperationInputFieldName);
0685: if (lInputField == null) {
0686: lInputField = mModelAssistantImpl.mOperationInputFieldClass
0687: .createOperationInputField();
0688: lInputField.setName(lOperationInputFieldName);
0689: lInputField.setOperation(lOperation);
0690: } else {
0691: lUnprocessedInputFields.remove(lInputField);
0692: }
0693: lInputField
0694: .setDescription(suggestProposedDetailsInputParameterDescription(pEntityName));
0695: lInputField.setArray(false);
0696: lInputField.setDataType(null);
0697: lInputField.setStructureType(lEntityDetailsStructure);
0698: }
0699: // Delete all input fields left
0700: for (Iterator lUnprocessedInputFieldsIterator = lUnprocessedInputFields
0701: .iterator(); lUnprocessedInputFieldsIterator
0702: .hasNext();) {
0703: OperationInputField lInputField = (OperationInputField) lUnprocessedInputFieldsIterator
0704: .next();
0705: if (!lInputField.isDerived())
0706: lInputField.refDelete();
0707: }
0708: }
0709: // Input constraints
0710: {
0711: // Copy aside the collection of the constraints, so we can delete the unused ones
0712: Collection lUnclaimedConstraints = new ArrayList();
0713: lUnclaimedConstraints.addAll(lOperation
0714: .getInputConstraints());
0715:
0716: String lOperationInputFieldName = suggestProposedDetailsInputParameterName(pEntityName);
0717: String lOperationInputFieldOCLFieldName = lOperationInputFieldName
0718: .substring(0, 1).toLowerCase()
0719: + lOperationInputFieldName.substring(1);
0720: // Work on the input presence validation constraint
0721: {
0722: String lConstraintName = lOperationInputFieldName
0723: + "FieldPresenceConstraint";
0724: ModelElementConstraint lModelElementConstraint = lOperation
0725: .findInputConstraint(lConstraintName);
0726: if (lModelElementConstraint == null) {
0727: lModelElementConstraint = mModelAssistantImpl.mModelElementConstraintClass
0728: .createModelElementConstraint();
0729: lModelElementConstraint.setName(lConstraintName);
0730: lOperation.getInputConstraints().add(
0731: lModelElementConstraint);
0732: } else {
0733: // Claim the field
0734: lUnclaimedConstraints
0735: .remove(lModelElementConstraint);
0736: }
0737: lModelElementConstraint
0738: .setDescription("Verifies that the "
0739: + lOperationInputFieldName
0740: + " input field is not empty in the operation input");
0741: lModelElementConstraint.setDefaultErrorText("The '"
0742: + lOperationInputFieldName
0743: + "' input field must not be empty.");
0744: lModelElementConstraint.setOclExpression("not "
0745: + lOperationInputFieldOCLFieldName
0746: + ".oclIsUndefined()");
0747: }
0748: // Work on the mandatory fields presence constraints.
0749: for (Iterator lAttributesIterator = pEntity
0750: .getCombinedAttributes().iterator(); lAttributesIterator
0751: .hasNext();) {
0752: Attribute lAttribute = (Attribute) lAttributesIterator
0753: .next();
0754: if (AttributeStereotypeEnum.MANDATORY.equals(lAttribute
0755: .getStereotype()))
0756: mandatoryAttributePresenceConstraint_EnsurePresent(
0757: lOperation, lOperationInputFieldName,
0758: lOperationInputFieldOCLFieldName,
0759: lAttribute.getName(), lUnclaimedConstraints);
0760: else
0761: mandatoryAttributePresenceConstraint_EnsureAbsent(
0762: lOperation, lOperationInputFieldName,
0763: lAttribute.getName(), lUnclaimedConstraints);
0764: }
0765: for (Iterator lReferencesIterator = pEntity
0766: .getCombinedReferences().iterator(); lReferencesIterator
0767: .hasNext();) {
0768: AssociationRole lReference = (AssociationRole) lReferencesIterator
0769: .next();
0770: if (lReference.isSingular() && lReference.isMandatory())
0771: mandatoryReferencePresenceConstraint_EnsurePresent(
0772: lOperation, lOperationInputFieldName,
0773: lOperationInputFieldOCLFieldName,
0774: lReference.getName(), lUnclaimedConstraints);
0775: else
0776: mandatoryReferencePresenceConstraint_EnsureAbsent(
0777: lOperation, lOperationInputFieldName,
0778: lReference.getName(), lUnclaimedConstraints);
0779: }
0780: // Remove unclaimed constraints
0781: for (Iterator lUnclaimedConstraintsIterator = lUnclaimedConstraints
0782: .iterator(); lUnclaimedConstraintsIterator
0783: .hasNext();) {
0784: ModelElementConstraint lUnclaimedConstraint = (ModelElementConstraint) lUnclaimedConstraintsIterator
0785: .next();
0786: if (!lUnclaimedConstraint.isDerived())
0787: lUnclaimedConstraint.refDelete();
0788: }
0789: }
0790: // Output Fields
0791: {
0792: Collection lOperationOutputFields = lOperation
0793: .getOutputFields();
0794: List lUnprocessedOutputFields = new ArrayList();
0795: lUnprocessedOutputFields.addAll(lOperationOutputFields);
0796: {
0797: String lOperationOutputFieldName = suggestCreatedDetailsReturnParameterName(pEntityName);
0798: OperationOutputField lOutputField = lOperation
0799: .findOutputField(lOperationOutputFieldName);
0800: if (lOutputField == null) {
0801: lOutputField = mModelAssistantImpl.mOperationOutputFieldClass
0802: .createOperationOutputField();
0803: lOutputField.setName(lOperationOutputFieldName);
0804: lOperationOutputFields.add(lOutputField);
0805: } else {
0806: lUnprocessedOutputFields.remove(lOutputField);
0807: }
0808: lOutputField
0809: .setDescription(suggestCreatedDetailsReturnParameterDescription(pEntityName));
0810: lOutputField.setArray(false);
0811: lOutputField.setDataType(null);
0812: lOutputField.setStructureType(lEntityDetailsStructure);
0813: }
0814: // Delete all output fields left
0815: for (Iterator lUnprocessedOutputFieldsIterator = lUnprocessedOutputFields
0816: .iterator(); lUnprocessedOutputFieldsIterator
0817: .hasNext();) {
0818: OperationOutputField lOutputField = (OperationOutputField) lUnprocessedOutputFieldsIterator
0819: .next();
0820: if (!lOutputField.isDerived())
0821: lOutputField.refDelete();
0822: }
0823: }
0824: // Output Messages
0825: {
0826: Collection lOperationOutputMessages = lOperation
0827: .getOutputMessages();
0828: List lUnprocessedOutputMessages = new ArrayList();
0829: lUnprocessedOutputMessages.addAll(lOperationOutputMessages);
0830:
0831: // If entity has primary key - it is possible to get creation error. Message has to be declared
0832: if (!pEntity.getPrimaryKeyElements().isEmpty()) {
0833: String lOperationOutputMessageName = suggestDuplicateCreateFailedReturnMessageName(pEntityName);
0834: OperationOutputMessage lOutputMessage = lOperation
0835: .findOutputMessage(lOperationOutputMessageName);
0836: if (lOutputMessage == null) {
0837: lOutputMessage = mModelAssistantImpl.mOperationOutputMessageClass
0838: .createOperationOutputMessage();
0839: lOutputMessage.setName(lOperationOutputMessageName);
0840: lOutputMessage.setOperation(lOperation);
0841: } else {
0842: lUnprocessedOutputMessages.remove(lOutputMessage);
0843: }
0844: lOutputMessage
0845: .setDescription(suggestDuplicateCreateFailedReturnMessageDescription(pEntityName));
0846: lOutputMessage.setArray(false);
0847: Message lDuplicateCreateFailedMessage = pDataManagementService
0848: .getServicemodule() != null ? pDataManagementService
0849: .getServicemodule()
0850: .findMessage(
0851: StylesheetImpl
0852: .getDuplicateCreateFailedMessageName(pEntityName))
0853: : null;
0854: lOutputMessage
0855: .setMessageType(lDuplicateCreateFailedMessage);
0856: }
0857:
0858: // We may have entity instances not found for the entities which may be specified during creation
0859: Set lEntitiesWhichMayBeNotFoundWhenCreatingInstance = new HashSet();
0860: Util
0861: .collectEntitiesWhichMayBeNotFoundWhenUpdatingOrCreatingInstance(
0862: pEntity,
0863: lEntitiesWhichMayBeNotFoundWhenCreatingInstance);
0864: for (Iterator lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenCreatingInstance
0865: .iterator(); lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator
0866: .hasNext();) {
0867: Entity lEntityElement = (Entity) lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator
0868: .next();
0869: String lEntityElementName = lEntityElement.getName();
0870: if (lEntityElementName == null)
0871: continue;
0872: String lOperationOutputMessageName = StylesheetImpl
0873: .getEntityNotFoundOperationOutputMessageName(lEntityElementName);
0874: OperationOutputMessage lOutputMessage = lOperation
0875: .findOutputMessage(lOperationOutputMessageName);
0876: if (lOutputMessage == null) {
0877: lOutputMessage = mModelAssistantImpl.mOperationOutputMessageClass
0878: .createOperationOutputMessage();
0879: lOutputMessage.setName(lOperationOutputMessageName);
0880: lOutputMessage.setOperation(lOperation);
0881: } else {
0882: lUnprocessedOutputMessages.remove(lOutputMessage);
0883: }
0884: lOutputMessage
0885: .setDescription(StylesheetImpl
0886: .getEntityNotFoundOperationOutputMessageDescription(lEntityElementName));
0887: lOutputMessage.setArray(false);
0888: Message lEntityInstanceNotFoundMessage = pDataManagementService
0889: .getServicemodule() != null ? pDataManagementService
0890: .getServicemodule()
0891: .findMessage(
0892: StylesheetImpl
0893: .getEntityInstanceNotFoundMessageName(lEntityElementName))
0894: : null;
0895: lOutputMessage
0896: .setMessageType(lEntityInstanceNotFoundMessage);
0897: }
0898:
0899: // Delete all output messages left
0900: for (Iterator lUnprocessedOutputMessagesIterator = lUnprocessedOutputMessages
0901: .iterator(); lUnprocessedOutputMessagesIterator
0902: .hasNext();) {
0903: OperationOutputMessage lOutputMessage = (OperationOutputMessage) lUnprocessedOutputMessagesIterator
0904: .next();
0905: if (!lOutputMessage.isDerived())
0906: lOutputMessage.refDelete();
0907: }
0908: }
0909: }
0910:
0911: // This helper makes sure that the version id attribute is absent in the details structure
0912: void ensureAbsent(Service pDataManagementService, String pEntityName) {
0913: // Work on the details structure
0914: Operation lOperation = pDataManagementService
0915: .findOperation(suggestOperationName(pEntityName));
0916: if (lOperation != null)
0917: lOperation.refDelete();
0918: }
0919:
0920: private void mandatoryAttributePresenceConstraint_EnsurePresent(
0921: Operation pOperation, String pOperationInputFieldName,
0922: String pOperationInputFieldOCLFieldName,
0923: String pAttributeName, Collection pUnclaimedConstraints) {
0924: String lAttributeFieldName = StylesheetImpl
0925: .getEntityAttributeStructureFieldName(pAttributeName);
0926: String lAttributeFieldOCLFieldName = lAttributeFieldName
0927: .substring(0, 1).toLowerCase()
0928: + lAttributeFieldName.substring(1);
0929: String lConstraintName = pOperationInputFieldName
0930: + lAttributeFieldName + "FieldPresenceConstraint";
0931: ModelElementConstraint lModelElementConstraint = pOperation
0932: .findInputConstraint(lConstraintName);
0933: if (lModelElementConstraint == null) {
0934: lModelElementConstraint = mModelAssistantImpl.mModelElementConstraintClass
0935: .createModelElementConstraint();
0936: lModelElementConstraint.setName(lConstraintName);
0937: pOperation.getInputConstraints().add(
0938: lModelElementConstraint);
0939: } else {
0940: // Claim the field if necessary
0941: if (pUnclaimedConstraints != null)
0942: pUnclaimedConstraints.remove(lModelElementConstraint);
0943: }
0944: lModelElementConstraint.setDescription("Ensures that the "
0945: + lAttributeFieldName
0946: + " mandatory field is populated in the "
0947: + pOperationInputFieldName + " structure.");
0948: lModelElementConstraint.setDefaultErrorText("The '"
0949: + lAttributeFieldName
0950: + "' field is mandatory and must be populated in the '"
0951: + pOperationInputFieldName + "' structure.");
0952: // Build and set the OCL expression
0953: StringBuffer lOCLExpression = new StringBuffer();
0954: lOCLExpression.append("not ");
0955: lOCLExpression.append(pOperationInputFieldOCLFieldName);
0956: lOCLExpression.append(".");
0957: lOCLExpression.append(lAttributeFieldOCLFieldName);
0958: lOCLExpression.append(".oclIsUndefined()");
0959: lModelElementConstraint.setOclExpression(lOCLExpression
0960: .toString());
0961: }
0962:
0963: private void mandatoryAttributePresenceConstraint_EnsureAbsent(
0964: Operation pOperation, String pOperationInputFieldName,
0965: String pAttributeName, Collection pUnclaimedConstraints) {
0966: String lAttributeFieldName = StylesheetImpl
0967: .getEntityAttributeStructureFieldName(pAttributeName);
0968: String lConstraintName = pOperationInputFieldName
0969: + lAttributeFieldName + "FieldPresenceConstraint";
0970: ModelElementConstraint lModelElementConstraint = pOperation
0971: .findInputConstraint(lConstraintName);
0972: if (lModelElementConstraint != null) {
0973: // Claim the field if necessary
0974: if (pUnclaimedConstraints != null)
0975: pUnclaimedConstraints.remove(lModelElementConstraint);
0976: lModelElementConstraint.refDelete();
0977: }
0978: }
0979:
0980: private void mandatoryReferencePresenceConstraint_EnsurePresent(
0981: Operation pOperation, String pOperationInputFieldName,
0982: String pOperationInputFieldOCLFieldName,
0983: String pReferenceName, Collection pUnclaimedConstraints) {
0984: String lReferenceFieldName = StylesheetImpl
0985: .getEntityReferenceStructureFieldName(pReferenceName);
0986: String lReferenceFieldOCLFieldName = lReferenceFieldName
0987: .substring(0, 1).toLowerCase()
0988: + lReferenceFieldName.substring(1);
0989: String lConstraintName = pOperationInputFieldName
0990: + lReferenceFieldName + "FieldPresenceConstraint";
0991: ModelElementConstraint lModelElementConstraint = pOperation
0992: .findInputConstraint(lConstraintName);
0993: if (lModelElementConstraint == null) {
0994: lModelElementConstraint = mModelAssistantImpl.mModelElementConstraintClass
0995: .createModelElementConstraint();
0996: lModelElementConstraint.setName(lConstraintName);
0997: pOperation.getInputConstraints().add(
0998: lModelElementConstraint);
0999: } else {
1000: // Claim the field if necessary
1001: if (pUnclaimedConstraints != null)
1002: pUnclaimedConstraints.remove(lModelElementConstraint);
1003: }
1004: lModelElementConstraint.setDescription("Ensures that the "
1005: + lReferenceFieldName
1006: + " mandatory field is populated in the "
1007: + pOperationInputFieldName + " structure.");
1008: lModelElementConstraint.setDefaultErrorText("The '"
1009: + lReferenceFieldName
1010: + "' field is mandatory and must be populated in the '"
1011: + pOperationInputFieldName + "' structure.");
1012: // Build and set the OCL expression
1013: StringBuffer lOCLExpression = new StringBuffer();
1014: lOCLExpression.append("not ");
1015: lOCLExpression.append(pOperationInputFieldOCLFieldName);
1016: lOCLExpression.append(".");
1017: lOCLExpression.append(lReferenceFieldOCLFieldName);
1018: lOCLExpression.append(".oclIsUndefined()");
1019: lModelElementConstraint.setOclExpression(lOCLExpression
1020: .toString());
1021: }
1022:
1023: private void mandatoryReferencePresenceConstraint_EnsureAbsent(
1024: Operation pOperation, String pOperationInputFieldName,
1025: String pReferenceName, Collection pUnclaimedConstraints) {
1026: String lReferenceFieldName = StylesheetImpl
1027: .getEntityReferenceStructureFieldName(pReferenceName);
1028: String lConstraintName = pOperationInputFieldName
1029: + lReferenceFieldName + "FieldPresenceConstraint";
1030: ModelElementConstraint lModelElementConstraint = pOperation
1031: .findInputConstraint(lConstraintName);
1032: if (lModelElementConstraint != null) {
1033: // Claim the field if necessary
1034: if (pUnclaimedConstraints != null)
1035: pUnclaimedConstraints.remove(lModelElementConstraint);
1036: lModelElementConstraint.refDelete();
1037: }
1038: }
1039:
1040: // This helper makes sure that the version id attribute is present in the details structure
1041: void duplicateCreateFailedMessage_EnsurePresent(
1042: Service pDataManagementService, String pEntityName) {
1043: String lOperationName = suggestOperationName(pEntityName);
1044: Operation lOperation = pDataManagementService
1045: .findOperation(lOperationName);
1046: if (lOperation == null)
1047: return; // Operation is not present yet
1048: String lOperationOutputMessageName = suggestDuplicateCreateFailedReturnMessageName(pEntityName);
1049: OperationOutputMessage lOutputMessage = lOperation
1050: .findOutputMessage(lOperationOutputMessageName);
1051: if (lOutputMessage == null) {
1052: lOutputMessage = mModelAssistantImpl.mOperationOutputMessageClass
1053: .createOperationOutputMessage();
1054: lOutputMessage.setName(lOperationOutputMessageName);
1055: lOutputMessage.setOperation(lOperation);
1056: }
1057: lOutputMessage
1058: .setDescription(suggestDuplicateCreateFailedReturnMessageDescription(pEntityName));
1059: lOutputMessage.setArray(false);
1060: Message lDuplicateCreateFailedMessage = pDataManagementService
1061: .getServicemodule() != null ? pDataManagementService
1062: .getServicemodule()
1063: .findMessage(
1064: StylesheetImpl
1065: .getDuplicateCreateFailedMessageName(pEntityName))
1066: : null;
1067: lOutputMessage.setMessageType(lDuplicateCreateFailedMessage);
1068: }
1069:
1070: // This helper makes sure that the version id attribute is absent in the details structure
1071: void duplicateCreateFailedMessage_EnsureAbsent(
1072: Service pDataManagementService, String pEntityName) {
1073: // Work on the details structure
1074: Operation lOperation = pDataManagementService
1075: .findOperation(suggestOperationName(pEntityName));
1076: if (lOperation == null)
1077: return; // Whole operation is absent
1078: String lOperationOutputMessageName = suggestDuplicateCreateFailedReturnMessageName(pEntityName);
1079: OperationOutputMessage lOutputMessage = lOperation
1080: .findOutputMessage(lOperationOutputMessageName);
1081: if (lOutputMessage != null)
1082: lOutputMessage.refDelete();
1083: }
1084:
1085: // Helper. Returns the message name
1086: private static String suggestOperationName(String pEntityName) {
1087: // Use normalised name here
1088: return "create"
1089: + StringUtils.suggestName(pEntityName, true, false);
1090: }
1091:
1092: // Helper. Returns the message description
1093: private static String suggestOperationDescription(String pEntityName) {
1094: // Use name 'as is' here
1095: return "Creates new instance of " + pEntityName
1096: + " in the domain.";
1097: }
1098:
1099: // Helper. Returns the name
1100: private static String suggestProposedDetailsInputParameterName(
1101: String pEntityName) {
1102: return "ProposedDetails";
1103: }
1104:
1105: // Helper. Returns the description
1106: private static String suggestProposedDetailsInputParameterDescription(
1107: String pEntityName) {
1108: // Use name 'as is' here
1109: return "Proposed details of the new instance of the "
1110: + pEntityName + " in the domain.";
1111: }
1112:
1113: // Helper. Returns the message name
1114: private static String suggestCreatedDetailsReturnParameterName(
1115: String pEntityName) {
1116: return "CreatedDetails";
1117: }
1118:
1119: // Helper. Returns the message description
1120: private static String suggestCreatedDetailsReturnParameterDescription(
1121: String pEntityName) {
1122: // Use name 'as is' here
1123: return "Details of an instance after successfull creation. Mostly the same as the details passed in, but will have some autogenerated fields populated.";
1124: }
1125:
1126: // Helper. Returns the message name
1127: private static String suggestDuplicateCreateFailedReturnMessageName(
1128: String pEntityName) {
1129: // Use normalised name here
1130: return "DuplicateKeyError";
1131: }
1132:
1133: // Helper. Returns the message description
1134: private static String suggestDuplicateCreateFailedReturnMessageDescription(
1135: String pEntityName) {
1136: // Use name 'as is' here
1137: return "Error message in case of failure or null if this error has not occurred.";
1138: }
1139: }
|