protected DataMapping findDataFlow(
      Interaction interaction, String parameterId, Direction direction)
      throws WebApplicationException {
    DataMapping ret = null;
    ApplicationContext definition = interaction.getDefinition();

    if ((null != definition) && !isEmpty(parameterId)) {
      AccessPoint outParam = findParameterDefinition(interaction, parameterId, direction);
      if (null == outParam) {
        if (InteractionDataFlowUtils.supportDataMappingIds()) {
          ret = definition.getDataMapping(direction, parameterId);
        }
      } else {
        List<DataMapping> allDataMappings = definition.getAllDataMappings();
        for (DataMapping dataMapping : allDataMappings) {
          if (outParam.equals(dataMapping.getApplicationAccessPoint())) {
            ret = dataMapping;
            break;
          }
        }
      }
    }

    if (ret == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    return ret;
  }
  /**
   * @param dataMapping
   * @param maPath
   * @return
   */
  private Path createStructureDataMapping(DataMapping dataMapping, ManualActivityPath maPath) {
    Set<TypedXPath> xpaths = ModelUtils.getXPaths(getModel(), dataMapping);

    for (TypedXPath path : xpaths) {
      if (path.getParentXPath() == null) {
        return new XsdPath(
            maPath, path, dataMapping.getId(), Direction.IN == dataMapping.getDirection());
      }
    }
    return null;
  }
  public void setData() {
    Map<String, Serializable> inDataValues =
        getWorkflowService()
            .getInDataValues(activityInstance.getOID(), getApplicationContext().getId(), null);

    for (Object object : getApplicationContext().getAllDataMappings()) {
      DataMapping dataMapping = (DataMapping) object;

      if (dataMapping.getDirection().equals(Direction.IN)
          || dataMapping.getDirection().equals(Direction.IN_OUT)) {
        Object value = inDataValues.get(dataMapping.getId());
        setValue(dataMapping.getId(), value);
      }
    }
  }
 /**
  * @param dataMapping
  * @return
  */
 private boolean isReadOnly(DataMapping dataMapping) {
   if (ModelUtils.isSystemDefinedReadOnlyData(dataMapping)) {
     return true;
   } else if (ModelUtils.isDMSReadOnlyData(getModel(), dataMapping)) {
     return true;
   }
   return Direction.IN == dataMapping.getDirection();
 }
  /** @return */
  public Map<String, Object> retrieveData() {
    Map<String, Object> map = new HashMap<String, Object>();

    for (Object object : getApplicationContext().getAllDataMappings()) {
      DataMapping dataMapping = (DataMapping) object;

      if (dataMapping.getDirection().equals(Direction.OUT)
          || dataMapping.getDirection().equals(Direction.IN_OUT)) {
        InputController inputCtrl = getTopLevelInputController(dataMapping.getId());
        Object value = getUnwrapValue(dataMapping.getId());

        // Handle Documents Specially
        if (null != value && inputCtrl instanceof DocumentInputController) {
          // Handle Unsaved Documents
          // Save Document, And if it's saved then again fetch the same and use it
          if (((DocumentInputController) inputCtrl).saveDocument()) {
            value = getUnwrapValue(dataMapping.getId());
          }
        }
        map.put(dataMapping.getId(), value);
      }
    }

    return map;
  }
  protected void setOutDataValueByMappingId(String parameterId, Object value) {
    Interaction interaction = findInteraction();

    DataMapping dm = findDataFlow(interaction, parameterId, Direction.OUT);

    UiInteractionsRestlet.trace.warn(
        "Writing OUT data using data mapping ID \""
            + parameterId
            + "\", this is only supported for a transition period.");

    Serializable decodedValue = unmarshalOutDataValue(interaction.getModel(), dm, value);
    if (null != decodedValue) {
      String outParamId = dm.getApplicationAccessPoint().getId();
      interaction.setOutDataValue(outParamId, decodedValue);
    } else {
      throw new WebApplicationException(Status.BAD_REQUEST);
    }
  }
  public Map getOutDataValues(ActivityInstance ai) {
    trace.info("JSP Application");
    HttpSession webSession =
        (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

    ApplicationContext applicationContext =
        ai.getActivity().getApplicationContext(PredefinedConstants.JSP_CONTEXT);

    Map outData = CollectionUtils.newMap();
    for (Iterator iterator = applicationContext.getAllOutDataMappings().iterator();
        iterator.hasNext() && webSession != null; ) {
      DataMapping mapping = (DataMapping) iterator.next();
      String mappingID = mapping.getId();
      outData.put(mappingID, webSession.getAttribute(mappingID));
    }

    return outData;
  }
  /* (non-Javadoc)
   * @see org.eclipse.stardust.ui.web.viewscommon.common.spi.IActivityInteractionController#unregisterInteraction(org.eclipse.stardust.engine.api.runtime.ActivityInstance)
   */
  public boolean unregisterInteraction(ActivityInstance ai) {
    HttpSession webSession =
        (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

    ApplicationContext applicationContext =
        ai.getActivity().getApplicationContext(PredefinedConstants.JSP_CONTEXT);

    if (applicationContext == null || webSession == null) {
      return false;
    }

    for (Iterator iterator = applicationContext.getAllOutDataMappings().iterator();
        iterator.hasNext(); ) {
      DataMapping mapping = (DataMapping) iterator.next();
      webSession.removeAttribute(mapping.getId());
    }

    return true;
  }
  public void initializePanel(ActivityInstance ai, Map inData) {
    HttpSession session =
        (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

    ApplicationContext applicationContext =
        ai.getActivity().getApplicationContext(PredefinedConstants.JSP_CONTEXT);

    for (Iterator i = applicationContext.getAllInDataMappings().iterator();
        i.hasNext() && session != null; ) {
      DataMapping mapping = (DataMapping) i.next();
      String mappingID = mapping.getId();
      Object value = inData.get(mappingID);

      if (trace.isDebugEnabled()) {
        trace.debug("Value " + value + " retrieved for mapping " + mappingID);
      }

      session.setAttribute(mappingID, value);
    }
  }
Exemplo n.º 10
0
 /**
  * @param dataMapping
  * @param allInMappings
  * @return
  */
 private boolean isWriteOnly(DataMapping dataMapping, List<Object> allInMappings) {
   if (Direction.IN == dataMapping.getDirection()
       || Direction.IN_OUT == dataMapping.getDirection()) {
     return false;
   } else if (Direction.OUT == dataMapping.getDirection()) {
     for (Object object : allInMappings) {
       DataMapping dm = (DataMapping) object;
       if (dm.getId().equals(dataMapping.getId())) {
         return false;
       }
     }
   }
   return true;
 }
Exemplo n.º 11
0
 /**
  * @param dataMapping
  * @param path
  * @param maPath
  * @return
  */
 private Path createPrimitiveDataMapping(DataMapping dataMapping, ManualActivityPath maPath) {
   return JavaPath.createFromClass(
       maPath, dataMapping.getId(), dataMapping.getMappedType(), isReadOnly(dataMapping));
 }
Exemplo n.º 12
0
 /**
  * @param dataMapping
  * @param maPath
  * @return
  */
 private Path createSystemDataMapping(DataMapping dataMapping, ManualActivityPath maPath) {
   return new IppSystemPath(maPath, dataMapping.getId(), isReadOnly(dataMapping));
 }
Exemplo n.º 13
0
  /**
   * @param dataMapping
   * @param allInMappings
   * @param maPath
   * @return
   */
  private Path createDMSDataMapping(
      DataMapping dataMapping, List<Object> allInMappings, ManualActivityPath maPath) {
    if (ModelUtils.isDocumentType(getModel(), dataMapping)) // Document
    {
      if (!isWriteOnly(dataMapping, allInMappings)) {
        DocumentType documentType =
            org.eclipse.stardust.ui.web.viewscommon.utils.ModelUtils.getDocumentTypeFromData(
                getModel(), getModel().getData(dataMapping.getDataId()));

        if (documentType == null) {
          trace.debug(
              "Could not resolve type for Document:, "
                  + dataMapping.getQualifiedId()
                  + ". It may be set defualt by design");
        }

        return new DocumentPath(
            maPath,
            dataMapping.getId(),
            documentType,
            null,
            Direction.IN == dataMapping.getDirection());
      } else {
        trace.warn(
            "Skipping Data Mapping - Found it as Write Only - "
                + dataMapping.getId()
                + ":"
                + dataMapping.getName());
      }
    } else if (ModelUtils.isFolderType(getModel(), dataMapping)) // Folder
    {
      // Skip, Not supported
    } else // Only Meta Data
    {
      Path docTypePath = null;
      Data documentData = getModel().getData(dataMapping.getDataId());
      String metaDataTypeId =
          (String) documentData.getAttribute(DmsConstants.RESOURCE_METADATA_SCHEMA_ATT);

      if (StringUtils.isNotEmpty(metaDataTypeId)) {
        TypeDeclaration typeDeclaration = getModel().getTypeDeclaration(metaDataTypeId);
        Set<TypedXPath> allXPaths = StructuredTypeRtUtils.getAllXPaths(getModel(), typeDeclaration);

        for (TypedXPath path : allXPaths) {
          if ("properties".equals(dataMapping.getDataPath())) // Mapping to entire properties
          {
            if (null == path.getParentXPath()) {
              docTypePath =
                  new XsdPath(
                      maPath,
                      path,
                      dataMapping.getId(),
                      Direction.IN == dataMapping.getDirection());
              break;
            }
          } else if (dataMapping
              .getDataPath()
              .equals("properties/" + path.getXPath())) // Mapping to nested item in properties
          {
            docTypePath =
                new XsdPath(
                    maPath, path, dataMapping.getId(), Direction.IN == dataMapping.getDirection());
            break;
          }
        }
      }

      // if null means - Mapping to documenmt's attributes e.g. id, owner, etc
      if (null == docTypePath) {
        // This is the only possibility, but still check
        if (ModelUtils.isPrimitiveType(getModel(), dataMapping)) {
          docTypePath = createPrimitiveDataMapping(dataMapping, maPath);
        }
      }

      return docTypePath;
    }

    return null;
  }
Exemplo n.º 14
0
  /*
   * Generates the top level panel for all Data Mappings of the Activity.
   */
  @SuppressWarnings("unchecked")
  public void generateForm() {
    List<Object> allOutMappings = getApplicationContext().getAllOutDataMappings();
    List<Object> allInMappings = getApplicationContext().getAllInDataMappings();

    // Process OUT Mappings first
    List<Object> allMappings = new ArrayList<Object>();
    allMappings.addAll(allOutMappings);
    allMappings.addAll(allInMappings);

    // Process All IN/OUT Mappings and collect all of them in ManualActivityPath
    Path path = null;
    ManualActivityPath manualActivityPath =
        new ManualActivityPath("MA" + activityInstance.getOID(), false);
    Map<Path, DataMapping> pathDataMappingMap = new HashMap<Path, DataMapping>();
    Map<String, DataMapping> dataMappingMap = new HashMap<String, DataMapping>();
    for (Object object : allMappings) {
      DataMapping dataMapping = (DataMapping) object;

      if (dataMappingMap.containsKey(dataMapping.getId())) {
        continue;
      }

      dataMappingMap.put(dataMapping.getId(), dataMapping);
      if (trace.isDebugEnabled()) {
        trace.debug(
            "Processing Data Mapping - " + dataMapping.getId() + ":" + dataMapping.getName());
      }

      // Handle Data Mapping as per Type
      if (ModelUtils.isSystemDefinedData(dataMapping)) {
        path = createSystemDataMapping(dataMapping, manualActivityPath);
      } else if (ModelUtils.isDMSType(getModel(), dataMapping)) {
        path = createDMSDataMapping(dataMapping, allInMappings, manualActivityPath);
      } else if (ModelUtils.isEnumerationType(getModel(), dataMapping)) {
        path = createStructureDataMapping(dataMapping, manualActivityPath);
      } else if (ModelUtils.isPrimitiveType(getModel(), dataMapping)) {
        path = createPrimitiveDataMapping(dataMapping, manualActivityPath);
      } else if (ModelUtils.isStructuredType(getModel(), dataMapping)) {
        path = createStructureDataMapping(dataMapping, manualActivityPath);
      }

      if (null != path) {
        manualActivityPath.getChildPaths().add(path);
        pathDataMappingMap.put(path, dataMapping);
      } else {
        trace.warn(
            "Skipping Data Mapping - Not supported - "
                + dataMapping.getId()
                + ":"
                + dataMapping.getName());
      }
    }

    // Set Label Provider along with required data for I18N
    formGenerator.setLabelProvider(new ManualActivityLabelProvider(getModel(), pathDataMappingMap));

    setRootContainer(formGenerator.createRootComponent());

    // Process ManualActivityPath and generate form
    processManualActivityPath(manualActivityPath, pathDataMappingMap);

    // Debug Information
    if (trace.isDebugEnabled()) {
      trace.debug("Full Path Map = " + getFullPathInputControllerMap());
      trace.debug("Top Level Map = " + getTopLevelInputControllerMap());
      trace.debug("Markup:\n" + generateMarkup());
    }
  }