Map<String, Object> getAuditLogItem(Object current) {
   DynaBean currentDynaBean = new WrapDynaBean(current);
   return propertiesToTrack
       .stream()
       .map(
           name -> {
             return CollectionUtils.entry(name, currentDynaBean.get(name));
           })
       .collect(CollectionUtils.nullSafeEntriesToMap());
 }
Example #2
0
  /**
   * Metodo auxiliar que define parametros comuns.
   *
   * @param buildDynaBean dyna bean de build.
   * @param build o build em si.
   */
  private void setCommonParams(final DynaBean buildDynaBean, final Build build) {
    // With tests
    build.setWithTests((Boolean) buildDynaBean.get(PARAM_WITH_TESTS));

    // Deploy
    build.setDeploy((Boolean) buildDynaBean.get(PARAM_DEPLOY));

    // Start & End Time
    final int buildTime = (Integer) buildDynaBean.get(PARAM_BUILD_TIME);
    final Date endTime = new Date();
    final Date startTime = new Date(endTime.getTime() - buildTime);
    build.setStartTime(startTime);
    build.setEndTime(endTime);
  }
Example #3
0
  /**
   * Cria build de modulos.
   *
   * @param data dados.
   * @param projectBuild projeto pai.
   */
  @SuppressWarnings("unchecked")
  private void createModulesBuild(final DynaBean data, final ProjectBuild projectBuild) {
    try {
      final List<DynaBean> modules = (List<DynaBean>) data.get(PARAM_MODULES);
      for (final DynaBean module : modules) {
        final String groupId = (String) module.get(PARAM_GROUP_ID);
        final String artifactId = (String) module.get(PARAM_ARTIFACT_ID);
        final String version = (String) module.get(PARAM_VERSION);
        final String projectName = (String) module.get(PARAM_PROJECT_NAME);

        final Project project = getProject(projectName, version, groupId, artifactId);

        final ModuleBuild moduleBuild = new ModuleBuild();
        moduleBuild.setProjectBuild(projectBuild);
        moduleBuild.setProject(project);

        // Parametros comuns
        setCommonParams(module, moduleBuild);

        // Adiciona modulo
        projectBuild.addModule(moduleBuild);
      }
      projectBuild.save();
    } catch (final MorphException e) {
      // Nao tem filhos, tudo bem
    }
  }
 Map<String, Object> getUpdatedAuditLogItem(Object current, Object updated) {
   DynaBean currentDynaBean = new WrapDynaBean(current);
   DynaBean updatedDynaBean = new WrapDynaBean(updated);
   return propertiesToTrack
       .stream()
       .map(
           name -> {
             Object currentValue = currentDynaBean.get(name);
             Object newValue = updatedDynaBean.get(name);
             if (areValuesEqual(currentValue, newValue)) {
               return CollectionUtils.entry(name, currentValue);
             } else {
               Map<String, Object> diffs =
                   Stream.of(
                           CollectionUtils.entry("old", currentValue),
                           CollectionUtils.entry("new", newValue))
                       .collect(CollectionUtils.nullSafeEntriesToMap());
               return CollectionUtils.entry(name, (Object) diffs);
             }
           })
       .collect(CollectionUtils.nullSafeEntriesToMap());
 }
  /** {@inheritDoc} */
  protected void setObject(
      PreparedStatement statement, int sqlIndex, DynaBean dynaBean, SqlDynaProperty property)
      throws SQLException {
    int typeCode = property.getColumn().getTypeCode();
    Object value = dynaBean.get(property.getName());

    // PostgreSQL doesn't like setNull for BYTEA columns
    if (value == null) {
      switch (typeCode) {
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
          statement.setBytes(sqlIndex, null);
          break;
        default:
          statement.setNull(sqlIndex, typeCode);
          break;
      }
    } else {
      super.setObject(statement, sqlIndex, dynaBean, property);
    }
  }
Example #6
0
  /**
   * Cria build de projeto pai com dados da requisicao.
   *
   * @param data dados.
   * @return build de projeto pai criado.
   */
  private ProjectBuild createProjectBuild(final DynaBean data) {
    // TODO (mmr) : trocar esse monte de binding com nome feio para um esquema de binding
    // automatico (colocar dominio em ponto comum entre Informer e Receiver)
    final DynaBean masterProject = (DynaBean) data.get(PARAM_MASTER_PROJECT);

    // Host
    final String hostName = (String) masterProject.get(PARAM_HOSTNAME);
    final String hostIp = (String) masterProject.get(PARAM_HOSTIP);
    final String operatingSystem = (String) masterProject.get(PARAM_OPERATING_SYSTEM);
    final String jvm = (String) masterProject.get(PARAM_JVM);
    final String encoding = (String) masterProject.get(PARAM_ENCODING);

    // User
    final String userName = (String) masterProject.get(PARAM_USERNAME);

    // Project
    final String projectName = (String) masterProject.get(PARAM_PROJECT_NAME);
    final String artifactId = (String) masterProject.get(PARAM_ARTIFACT_ID);
    final String groupId = (String) masterProject.get(PARAM_GROUP_ID);
    final String version = (String) masterProject.get(PARAM_VERSION);

    final ProjectBuild projectBuild = new ProjectBuild();

    final User user = getUser(userName);
    projectBuild.setUser(user);

    final Host host = getHost(hostName, hostIp, jvm, encoding, operatingSystem);
    projectBuild.setHost(host);

    final Project project = getProject(projectName, version, groupId, artifactId);
    projectBuild.setProject(project);

    // Parametros comuns
    setCommonParams(masterProject, projectBuild);

    // Save
    projectBuild.save();
    return projectBuild;
  }
  /**
   * 导出材料使用年统计数据
   *
   * @param list
   * @param excelstyle
   */
  public void doExportModel(List list, ExcelStyle excelstyle) {
    DynaBean record;
    activeSheet(0);
    super.curStyle = excelstyle.defaultStyle(super.workbook);
    int r = 3; // 行索引
    if (list != null && list.size() > 0) {
      Iterator iter = list.iterator();
      while (iter.hasNext()) {
        record = (DynaBean) iter.next();
        activeRow(r);
        if (record.get("modelname") == null) {
          setCellValue(0, "");
        } else {
          setCellValue(0, record.get("modelname").toString());
        }
        if (record.get("typename") == null) {
          setCellValue(1, "");
        } else {
          setCellValue(1, record.get("typename").toString());
        }
        if (record.get("unit") == null) {
          setCellValue(2, "");
        } else {
          setCellValue(2, record.get("unit").toString());
        }
        /*if (record.get("unit") == null) {
        	setCellValue(2, "");
        } else {
        	setCellValue(2, record.get("unit").toString());
        }*/
        setCellValue(3, 0 + "");

        if (record.get("use_number") == null) {
          setCellValue(4, "");
        } else {
          setCellValue(4, record.get("use_number").toString());
        }

        if (record.get("jan") == null) {
          setCellValue(5, "");
        } else {
          setCellValue(5, record.get("jan").toString());
        }
        if (record.get("feb") == null) {
          setCellValue(6, "");
        } else {
          setCellValue(6, record.get("feb").toString());
        }
        if (record.get("mar") == null) {
          setCellValue(7, "");
        } else {
          setCellValue(7, record.get("mar").toString());
        }
        if (record.get("apr") == null) {
          setCellValue(8, "");
        } else {
          setCellValue(8, record.get("apr").toString());
        }
        if (record.get("may") == null) {
          setCellValue(9, "");
        } else {
          setCellValue(9, record.get("may").toString());
        }
        if (record.get("june") == null) {
          setCellValue(10, "");
        } else {
          setCellValue(10, record.get("june").toString());
        }
        if (record.get("july") == null) {
          setCellValue(11, "");
        } else {
          setCellValue(11, record.get("july").toString());
        }
        if (record.get("aug") == null) {
          setCellValue(12, "");
        } else {
          setCellValue(12, record.get("aug").toString());
        }
        if (record.get("sep") == null) {
          setCellValue(13, "");
        } else {
          setCellValue(13, record.get("sep").toString());
        }
        if (record.get("oct") == null) {
          setCellValue(14, "");
        } else {
          setCellValue(14, record.get("oct").toString());
        }
        if (record.get("nov") == null) {
          setCellValue(15, "");
        } else {
          setCellValue(15, record.get("nov").toString());
        }
        if (record.get("dece") == null) {
          setCellValue(16, "");
        } else {
          setCellValue(16, record.get("dece").toString());
        }

        r++;
      }
    }
  }
Example #8
0
  protected void toUpperCase(Object form, HttpServletRequest request)
      throws IllegalAccessException, InvocationTargetException {

    if (Utils.isDBCaseSensitive(request)) {

      String[] attrs = getAttrsToUpper();

      if ((attrs != null) && (attrs.length > 0)) {
        if (form instanceof DynaBean) {
          DynaProperty formDescriptors[] = ((DynaBean) form).getDynaClass().getDynaProperties();
          for (int i = 0; i < formDescriptors.length; i++) {
            String name = formDescriptors[i].getName();
            Object value = ((DynaBean) form).get(name);

            if (value instanceof String) {
              if (isAttrTuUpper(attrs, name)) {
                value = ((String) value).toUpperCase();
                ((DynaBean) form).set(name, value);
              }
            }
          }
        } else if (form instanceof Map) {
          Iterator names = ((Map) form).keySet().iterator();
          while (names.hasNext()) {
            String name = (String) names.next();
            Object value = ((Map) form).get(name);

            if (value instanceof String) {
              if (isAttrTuUpper(attrs, name)) {
                value = ((String) value).toUpperCase();
                ((Map) form).put(name, value);
              }
            }
          }
        } else /* if (orig is a standard JavaBean) */ {
          PropertyDescriptor origDescriptors[] =
              BeanUtilsBean.getInstance().getPropertyUtils().getPropertyDescriptors(form);
          for (int i = 0; i < origDescriptors.length; i++) {
            String name = origDescriptors[i].getName();

            if ("class".equals(name)) {
              continue; // No point in trying to set an object's
              // class
            }

            if (BeanUtilsBean.getInstance().getPropertyUtils().isReadable(form, name)) {
              try {
                Object value =
                    BeanUtilsBean.getInstance().getPropertyUtils().getSimpleProperty(form, name);
                if (value instanceof String) {
                  if (isAttrTuUpper(attrs, name)) {
                    value = ((String) value).toUpperCase();
                    BeanUtilsBean.getInstance()
                        .getPropertyUtils()
                        .setSimpleProperty(form, name, value);
                  }
                }

              } catch (NoSuchMethodException e) {; // Should not happen
              }
            }
          }
        }
      }
    }
  }
Example #9
-1
  public void testCreate() throws ArooaParseException {

    OurDirs dirs = new OurDirs();

    File testFile = dirs.relative("work/test.txt");

    String xml =
        "<echo name='Test' ><![CDATA[Hello]]>"
            + " <output>"
            + "  <file file='"
            + testFile.getPath()
            + "'/>"
            + " </output>"
            + "</echo>";

    ArooaDescriptor descriptor =
        new OddjobDescriptorFactory().createDescriptor(getClass().getClassLoader());

    DesignParser parser = new DesignParser(new StandardArooaSession(descriptor));
    parser.setArooaType(ArooaType.COMPONENT);

    parser.parse(new XMLConfiguration("TEST", xml));

    design = parser.getDesign();

    assertEquals(EchoDesign.class, design.getClass());

    DynaBean test =
        (DynaBean)
            OddjobTestHelper.createComponentFromConfiguration(
                design.getArooaContext().getConfigurationNode());

    assertEquals("Test", test.get("name"));
    assertEquals("Hello", test.get("text"));
  }
Example #10
-1
  private void copy(final Directory directory, final Map<String, Object> metadata) {
    final TagDescriptor<?> descriptor = MetadataHelper.getDescriptor(directory);

    final LazyDynaClass directoryClass =
        new LazyDynaClass(
            directory.getName(),
            null,
            directory
                .getTags()
                .parallelStream()
                .map(
                    t ->
                        new DynaProperty(
                            t.getTagName().replaceAll(NON_WORD_CHARS, ""), String.class))
                .toArray(DynaProperty[]::new));
    directoryClass.setReturnNull(true);

    final DynaBean directoryMetadata = new LazyDynaBean(directoryClass);
    directory
        .getTags()
        .stream()
        .forEach(
            t ->
                directoryMetadata.set(
                    t.getTagName().replaceAll(NON_WORD_CHARS, ""),
                    descriptor.getDescription(t.getTagType())));
    metadata.put(directory.getName().replaceAll(NON_WORD_CHARS, ""), directoryMetadata);
  }
Example #11
-1
 /**
  * 在List中查找含有key的名称 DynaBean
  *
  * @param patrollist
  * @param key
  * @return
  */
 public String searchDynaPatrol(List patrollist, String key) {
   String value = "";
   for (int j = 0; j < patrollist.size(); j++) {
     DynaBean pmb = (DynaBean) patrollist.get(j);
     if (pmb.get("id").equals(key)) value = (String) pmb.get("patrolname");
   }
   return value;
 }