Exemplo n.º 1
0
  /**
   * sets the parent id of masterdata records.
   *
   * @param iGenericObjectId
   */
  @Override
  public void setParent(
      String moduleEntityName,
      Integer iGenericObjectId,
      Map<EntityAndFieldName, String> collSubEntities) {
    if (iGenericObjectId == null) {
      throw new NullArgumentException("iGenericObjectId");
    }

    Long longId = IdUtils.toLongId(iGenericObjectId);
    /** @todo eliminate this workaround: */
    final MasterDataMetaProvider cache =
        SpringApplicationContextHolder.getBean(MasterDataMetaProvider.class);
    for (String sEntityName : this.getEntityNames()) {
      if (cache != null) {
        final MasterDataMetaVO mdmetavo = cache.getMetaData(sEntityName);
        if (mdmetavo.isEditable()) {
          for (EntityObjectVO mdvo : this.getData(sEntityName)) {
            String foreignKeyIdField = null;
            for (EntityAndFieldName entityAndFieldName : collSubEntities.keySet()) {
              if (entityAndFieldName.getEntityName().equals(sEntityName)) {
                foreignKeyIdField = entityAndFieldName.getFieldName();
                break;
              }
            }
            if (foreignKeyIdField == null)
              foreignKeyIdField = getForeignKeyField(mdmetavo, moduleEntityName, false);
            final Long iOldGenericObjectId = mdvo.getFieldId(foreignKeyIdField);
            if (iOldGenericObjectId != null && !longId.equals(iOldGenericObjectId)) {
              log.warn(
                  "Bad parent id in dependant masterdata record; old id: "
                      + iOldGenericObjectId
                      + ", new id: "
                      + longId
                      + ".");
            }
            if (iOldGenericObjectId == null
                || (!longId.equals(iOldGenericObjectId) && mdvo.isFlagUpdated())) {
              mdvo.getFieldIds().put(foreignKeyIdField, longId);
            }
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  public ImportStructure(Integer iImportStructureId) {
    try {
      final MasterDataFacadeLocal mdfacade =
          ServerServiceLocator.getInstance().getFacade(MasterDataFacadeLocal.class);

      final MasterDataVO mdcvoStructure =
          mdfacade.get(NuclosEntity.IMPORT.getEntityName(), iImportStructureId);

      this.name = (String) mdcvoStructure.getField("name");
      this.sDelimiter = (String) mdcvoStructure.getField("delimiter");
      this.sEncoding = (String) mdcvoStructure.getField("encoding");
      this.iHeaderLineCount = (Integer) mdcvoStructure.getField("headerlines");
      this.bInsert = (Boolean) mdcvoStructure.getField("insert");
      this.bUpdate = (Boolean) mdcvoStructure.getField("update");
      this.bDelete = (Boolean) mdcvoStructure.getField("delete");

      this.iEntityId = (Integer) mdcvoStructure.getField("entityId");

      this.items = new HashMap<String, Item>();
      final Collection<MasterDataVO> collAttributes =
          mdfacade.getDependantMasterData(
              NuclosEntity.IMPORTATTRIBUTE.getEntityName(), "import", iImportStructureId);

      final String entityname =
          MetaDataServerProvider.getInstance()
              .getEntity(IdUtils.toLongId(this.iEntityId))
              .getEntity();
      this.entityname = entityname;
      final boolean isModule = Modules.getInstance().existModule(entityname);

      for (MasterDataVO mdcvo : collAttributes) {
        final Integer iIndex = (Integer) mdcvo.getField("fieldcolumn");
        final String attribute = (String) mdcvo.getField("attribute");
        final String format = (String) mdcvo.getField("parsestring");
        final boolean preserve = (Boolean) mdcvo.getField("preserve");
        final NuclosScript script = (NuclosScript) mdcvo.getField("script");
        final Class<?> clazz;

        String foreignentity = null;
        if (isModule) {
          AttributeCVO meta = AttributeCache.getInstance().getAttribute(entityname, attribute);
          clazz = meta.getJavaClass();
          foreignentity = meta.getExternalEntity();
        } else {
          MasterDataMetaFieldVO meta =
              MasterDataMetaCache.getInstance().getMetaData(entityname).getField(attribute);
          clazz = meta.getJavaClass();
          foreignentity = meta.getForeignEntity();
        }

        final Set<ForeignEntityIdentifier> foreignentityattributes =
            new HashSet<ImportStructure.ForeignEntityIdentifier>();

        if (foreignentity != null
            && !attribute.equals(NuclosEOField.PROCESS.getMetaData().getField())
            && !attribute.equals(NuclosEOField.STATE.getMetaData().getField())) {
          final boolean isFeModule = Modules.getInstance().existModule(foreignentity);

          final Collection<MasterDataVO> collForeignEntityIdentifiers =
              mdfacade.getDependantMasterData(
                  NuclosEntity.IMPORTFEIDENTIFIER.getEntityName(),
                  "importattribute",
                  mdcvo.getIntId());

          for (MasterDataVO mdvo : collForeignEntityIdentifiers) {
            final Integer iColumn = (Integer) mdvo.getField("fieldcolumn");
            final String feattribute = (String) mdvo.getField("attribute");
            final String feformat = (String) mdvo.getField("parsestring");
            final Class<?> feclazz;

            if (isFeModule) {
              AttributeCVO meta =
                  AttributeCache.getInstance().getAttribute(foreignentity, feattribute);
              feclazz = meta.getJavaClass();
            } else {
              MasterDataMetaFieldVO meta =
                  MasterDataMetaCache.getInstance()
                      .getMetaData(foreignentity)
                      .getField(feattribute);
              feclazz = meta.getJavaClass();
            }

            foreignentityattributes.add(
                new ForeignEntityIdentifier(
                    iColumn, foreignentity, feattribute, feclazz, feformat));
          }
        } else {
          foreignentity = null;
        }

        this.items.put(
            attribute,
            new ImportStructure.Item(
                iIndex,
                entityname,
                attribute,
                clazz,
                format,
                preserve,
                foreignentity,
                foreignentityattributes,
                script));
      }

      final Collection<MasterDataVO> collIdentifiers =
          mdfacade.getDependantMasterData(
              NuclosEntity.IMPORTIDENTIFIER.getEntityName(), "import", iImportStructureId);
      for (final MasterDataVO mdcvo : collIdentifiers) {
        this.stIdentifiers.add((String) mdcvo.getField("attribute"));
      }
    } catch (CommonPermissionException ex) {
      throw new NuclosFatalException(ex);
    } catch (CommonFinderException ex) {
      throw new NuclosFatalException(ex);
    }
  }