Esempio n. 1
0
    /** 根据视图同步定义的columnPair,获取需要反查的字段列表,不包括主键 */
    private List<String> buildMaxColumnsFromColumnPairs(
        List<DataMediaPair> mediaPairs, List<EventColumn> pks) {
      Set<String> allColumns = new HashSet<String>();
      Map<String, EventColumn> pkMap = new HashMap<String, EventColumn>(pks.size(), 1f);
      for (EventColumn pk : pks) {
        pkMap.put(StringUtils.lowerCase(pk.getColumnName()), pk);
      }

      for (DataMediaPair mediaPair : mediaPairs) { // 一个源库可以对应多个目标,多路复制
        List<ColumnPair> columnPairs = mediaPair.getColumnPairs();

        if (CollectionUtils.isEmpty(columnPairs) || mediaPair.getColumnPairMode().isExclude()) {
          // 1. 如果有一个没有视图定义,说明需要所有字段
          // 2. 如果有一个表存在exclude模式,简单处理,直接反查所有字段,到后面进行过滤
          return new ArrayList<String>(); // 返回空集合,代表没有view
          // filter,需要所有字段
        } else {
          for (ColumnPair columnPair : columnPairs) {
            String columnName = columnPair.getSourceColumn().getName();
            if (!pkMap.containsKey(StringUtils.lowerCase(columnName))) {
              allColumns.add(columnPair.getSourceColumn().getName()); // 加入的为非主键
            }
          }
        }
      }

      return new ArrayList<String>(allColumns);
    }
Esempio n. 2
0
  /**
   * 设置排序方式向.
   *
   * @param order 可选值为desc或asc,多个排序字段时用','分隔.
   */
  public void setOrder(final String order) {
    // 检查order字符串的合法值
    String[] orders = StringUtils.split(StringUtils.lowerCase(order), ',');
    for (String orderStr : orders) {
      if (!StringUtils.equals(DESC, orderStr) && !StringUtils.equals(ASC, orderStr))
        throw new IllegalArgumentException("排序方向 " + orderStr + "不是合法值 ");
    }

    this.order = StringUtils.lowerCase(order);
  }
Esempio n. 3
0
  public static UUID getIndexId(
      EntityRef connectingEntity,
      String connectionType,
      String connectedEntityType,
      ConnectedEntityRef... pairedConnections) {

    UUID uuid = null;
    try {

      if (connectionsNull(pairedConnections)
          && ((connectionType == null) && (connectedEntityType == null))) {
        return connectingEntity.getUuid();
      }

      ByteArrayOutputStream byteStream =
          new ByteArrayOutputStream(16 + (32 * pairedConnections.length));

      byteStream.write(uuidToBytesNullOk(connectingEntity.getUuid()));

      for (ConnectedEntityRef connection : pairedConnections) {
        String type = connection.getConnectionType();
        UUID id = connection.getUuid();

        byteStream.write(ascii(StringUtils.lowerCase(type)));
        byteStream.write(uuidToBytesNullOk(id));
      }

      if (connectionType == null) {
        connectionType = NULL_ENTITY_TYPE;
      }
      if (connectedEntityType == null) {
        connectedEntityType = NULL_ENTITY_TYPE;
      }

      byteStream.write(ascii(StringUtils.lowerCase(connectionType)));
      byteStream.write(ascii(StringUtils.lowerCase(connectedEntityType)));

      byte[] raw_id = byteStream.toByteArray();

      logger.info("raw connection index id: " + Hex.encodeHexString(raw_id));

      uuid = UUID.nameUUIDFromBytes(raw_id);

      logger.info("connection index uuid: " + uuid);
    } catch (IOException e) {
      logger.error("Unable to create connection index UUID", e);
    }
    return uuid;
  }
  /**
   * 转换成骆驼命名法返回
   *
   * @param name
   * @return
   */
  public static String getCamelName(String name) {
    if (StringUtils.isBlank(name)) {
      return null;
    }
    name = StringUtils.lowerCase(name);
    // 去掉前面的_
    while (StringUtils.startsWith(name, "_")) {
      name = StringUtils.substring(name, 1);
    }
    // 去掉后面的_
    while (StringUtils.endsWith(name, "_")) {
      name = StringUtils.substring(name, 0, name.length() - 1);
    }

    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < name.length(); i++) {

      char c = name.charAt(i);

      if (c == '_') {
        i++;
        sb.append(Character.toUpperCase(name.charAt(i)));
        continue;
      }
      sb.append(c);
    }

    return sb.toString();
  }
 private void addLink(
     Study study,
     Map<Integer, Term> stageForNode,
     Map<Integer, String> taxonForNode,
     LabeledCSVParser links,
     Location location)
     throws StudyImporterException, NodeFactoryException {
   Integer consumerNodeID = Integer.parseInt(links.getValueByLabel("ConsumerNodeID"));
   Integer resourceNodeID = Integer.parseInt(links.getValueByLabel("ResourceNodeID"));
   String linkType = links.getValueByLabel("LinkType");
   InteractType interactType =
       interactionMapping.get(StringUtils.trim(StringUtils.lowerCase(linkType)));
   if (interactType == null) {
     throw new StudyImporterException(
         "failed to map interaction type ["
             + linkType
             + "] in line ["
             + links.lastLineNumber()
             + "]");
   }
   Specimen consumer = nodeFactory.createSpecimen(study, taxonForNode.get(consumerNodeID));
   consumer.setLifeStage(stageForNode.get(consumerNodeID));
   consumer.setExternalId(getNamespace() + ":NodeID:" + consumerNodeID);
   consumer.caughtIn(location);
   String resourceName = taxonForNode.get(resourceNodeID);
   Specimen resource = nodeFactory.createSpecimen(study, resourceName);
   resource.setLifeStage(stageForNode.get(resourceNodeID));
   resource.setExternalId(getNamespace() + ":NodeID:" + resourceNodeID);
   resource.caughtIn(location);
   consumer.interactsWith(resource, interactType);
 }
  public void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String redirectFrom =
        StringUtils.lowerCase(
            ServletRequestUtils.getRequiredStringParameter(request, "redirectFrom"));

    Redirection redirection = redirectionDao.getRedirection(redirectFrom);
    if (redirection == null) {
      response.sendError(
          HttpServletResponse.SC_BAD_REQUEST,
          "Web address " + redirectFrom + ".subsonic.org not registered.");
      return;
    }

    PrintWriter writer = response.getWriter();
    String url = redirection.getRedirectTo();
    if (!url.endsWith("/")) {
      url += "/";
    }
    writer.println(url);

    url = redirection.getLocalRedirectTo();
    if (!url.endsWith("/")) {
      url += "/";
    }
    writer.println(url);
  }
Esempio n. 7
0
 /**
  * Log a step into test case result.
  *
  * @param tcName
  * @param result
  * @param msg
  */
 public void logStep(String tcName, String result, String msg) {
   if ("".equals(tcName)) {
     tcName = oi.logRunningTC;
     if (!"".equals(result.trim())) {
       if ("false".equals(StringUtils.lowerCase(result.trim()))) {
         oi.logList.add(
             tcName
                 + ","
                 + result.trim()
                 + ",At step "
                 + init.currentStep
                 + " of "
                 + init.sumStep
                 + ","
                 + msg.trim());
       } else {
         oi.logList.add(tcName + "," + result.trim() + "," + msg.trim());
       }
     }
   } else {
     if (StringUtils.left(tcName, 4).equals("test")) {
       tcName = StringUtils.mid(tcName, 4, tcName.length());
     }
     oi.logRunningTC = tcName;
     if ("".equals(result.trim())) {
       oi.logList.add(tcName + "," + init.logTcStart);
     } else {
       oi.logList.add(tcName + "," + result.trim());
     }
   }
 }
 protected String getView(final T component) {
   // build a jsp response based on the given view name otherwise use the component type
   return ControllerConstants.Views.Cms.ComponentPrefix
       + StringUtils.lowerCase(
           !StringUtils.isEmpty(component.getViewName())
               ? component.getViewName()
               : getTypeCode(component));
 }
 @Test
 public void testRenderComponent() throws Exception {
   final ExtendedModelMap model = new ExtendedModelMap();
   final String viewName =
       miniCartComponentController.handleComponent(
           request, response, model, miniCartComponentModel);
   Assert.assertEquals(
       ControllerConstants.Views.Cms.ComponentPrefix
           + StringUtils.lowerCase(miniCartComponentModel.getItemtype()),
       viewName);
 }
Esempio n. 10
0
 private Header createHeader(
     String binlogFile, LogHeader logHeader, String schemaName, String tableName) {
   // header会做信息冗余,方便以后做检索或者过滤
   Header.Builder headerBuilder = Header.newBuilder();
   headerBuilder.setVersion(version);
   headerBuilder.setLogfileName(binlogFile);
   headerBuilder.setLogfileOffset(logHeader.getLogPos() - logHeader.getEventLen());
   headerBuilder.setServerId(logHeader.getServerId());
   headerBuilder.setServerenCode(UTF_8); // 经过java输出后所有的编码为unicode
   headerBuilder.setExecuteTime(logHeader.getWhen() * 1000L);
   headerBuilder.setSourceType(Type.MYSQL);
   if (schemaName != null) {
     headerBuilder.setSchemaName(StringUtils.lowerCase(schemaName));
   }
   if (tableName != null) {
     headerBuilder.setTableName(StringUtils.lowerCase(tableName));
   }
   headerBuilder.setEventLength(logHeader.getEventLen());
   return headerBuilder.build();
 }
Esempio n. 11
0
 public static String cleanWWN(String wwn) {
   if (StringUtils.isBlank(wwn)) {
     return null;
   }
   wwn = StringUtils.lowerCase(StringUtils.trim(wwn));
   if (!LOOSE_WWN_PATTERN.matcher(wwn).matches()) {
     return null;
   }
   wwn = StringUtils.replace(wwn, ":", "");
   return wwn;
 }
Esempio n. 12
0
  @SuppressWarnings("unchecked")
  public <T> T getBean(Class<T> clazz) {
    if (appContext != null) {
      String className = clazz.getSimpleName();
      String startName = className.substring(0, 1);
      String otherName = className.substring(1);

      String beanName = StringUtils.lowerCase(startName) + otherName;
      return (T) appContext.getBean(beanName);
    }
    return null;
  }
Esempio n. 13
0
 /**
  * 登陆验证码校验
  *
  * @param captchaCode
  * @return
  */
 public boolean checkCaptchaCode(String captchaCode) {
   if (StringUtils.isNotBlank(captchaCode)) {
     String captchaKey = Constants.REDIS_KEY_CAPTCHA_PREFIX + StringUtils.lowerCase(captchaCode);
     boolean checkFlag = redisEao.isKeyExist(captchaKey);
     System.out.println(checkFlag + "---------");
     if (checkFlag) {
       redisEao.del(captchaKey);
       return true;
     }
   }
   return false;
 }
 /**
  * DOC yyin Comment method "findCreatedTable".
  *
  * @param hiveConnectionItem
  * @param createTableName
  * @return
  */
 private DBTableRepNode findCreatedTable(
     DatabaseConnectionItem hiveConnectionItem, String createTableName) {
   if (hiveConnectionItem == null) {
     return null;
   }
   // TDQ-10462 the table from the hive connection, only use lowercase.
   IRepositoryNode tableNode =
       TableUtils.findTableInConnection(
           hiveConnectionItem, StringUtils.lowerCase(createTableName));
   if (tableNode != null && tableNode instanceof DBTableRepNode) {
     return (DBTableRepNode) tableNode;
   }
   return null;
 }
 private void appendResourceNameCondition(StringBuilder sb) {
   if (StringUtils.isNotBlank(filter.getResourceName())) {
     sb.append(
         " AND s.project_id IN (SELECT rindex.resource_id FROM resource_index rindex WHERE rindex.kee LIKE '");
     sb.append(
         escapePercentAndUnderscrore(
             StringEscapeUtils.escapeSql(StringUtils.lowerCase(filter.getResourceName()))));
     sb.append("%'");
     appendEscapeForSomeDb(sb);
     if (!filter.getResourceQualifiers().isEmpty()) {
       sb.append(" AND rindex.qualifier IN ");
       appendInStatement(filter.getResourceQualifiers(), sb);
     }
     sb.append(") ");
   }
 }
Esempio n. 16
0
  private ForcedResolverValueLifetimeSettings getForcedDeviceClassSetting(
      ExtendedMap formItems, ForcedResolverValueLifetimeSettings defaultSetting) {

    String forcedDeviceClassParameter =
        formItems.getString(FORCE_VALUE_SETTING_KEY, defaultSetting.name());

    ForcedResolverValueLifetimeSettings forcedDeviceClassSetting;
    try {
      forcedDeviceClassSetting =
          ForcedResolverValueLifetimeSettings.valueOf(
              StringUtils.lowerCase(forcedDeviceClassParameter));
    } catch (IllegalArgumentException e) {
      throw new VerticalUserServicesException(
          "Force deviceclass setting is invalid: " + forcedDeviceClassParameter);
    }
    return forcedDeviceClassSetting;
  }
Esempio n. 17
0
  /**
   * @param resourceDTO
   * @param siteId
   * @param comment
   * @return
   * @throws IOException
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(
      value = "/bender/{siteId:.+}/resource",
      method = RequestMethod.POST,
      headers = {"content-type=application/json"})
  public ResponseEntity<BenderResource> createResource(
      @RequestBody @Valid BenderResource resourceDTO,
      @PathVariable("siteId") String siteId,
      @RequestParam(value = "comment", required = false) String comment)
      throws IOException, ValidationException {

    ResponseEntity<BenderResource> result =
        new ResponseEntity<>(null, new HttpHeaders(), HttpStatus.BAD_REQUEST);

    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("Le site est inconnu");
    }

    User user = userService.getConnected();
    resourceDTO.setSite(siteId);
    resourceDTO.setCreationDate(new Date());
    resourceDTO.setUpdateDate(new Date());
    // set Resource Path
    // format path with Path.get
    resourceDTO.setPath(
        Paths.get(
                resourceDTO.getPath()
                    + File.separator
                    + resourceDTO.getName()
                    + "."
                    + StringUtils.lowerCase(resourceDTO.getType()))
            .toString());
    BenderResource createdResource = benderService.persist(resourceDTO);
    if (createdResource != null)
      result =
          new ResponseEntity<>(
              this.getResourceById(createdResource.getId(), null, siteId),
              new HttpHeaders(),
              HttpStatus.OK);

    return result;
  }
  protected void doSubmitAction(Object cmd) throws Exception {
    NetworkSettingsCommand command = (NetworkSettingsCommand) cmd;

    settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled());
    settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled());
    settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom()));

    if (!settingsService.isLicenseValid() && settingsService.getUrlRedirectTrialExpires() == null) {
      Date expiryDate = new Date(System.currentTimeMillis() + TRIAL_DAYS * 24L * 3600L * 1000L);
      settingsService.setUrlRedirectTrialExpires(expiryDate);
    }

    if (settingsService.getServerId() == null) {
      Random rand = new Random(System.currentTimeMillis());
      settingsService.setServerId(String.valueOf(Math.abs(rand.nextLong())));
    }

    settingsService.save();
    networkService.initPortForwarding();
    networkService.initUrlRedirection(true);
  }
Esempio n. 19
0
  @Override
  protected void handlerCustom(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      ExtendedMap formItems,
      UserServicesService userServices,
      SiteKey siteKey,
      String operation)
      throws VerticalUserServicesException, VerticalEngineException, IOException,
          ClassNotFoundException, IllegalAccessException, InstantiationException, ParseException {

    PortalOperation portalOperation = null;
    try {
      portalOperation = PortalOperation.valueOf(StringUtils.lowerCase(operation));
    } catch (IllegalArgumentException e) {
      throw new VerticalUserServicesException(
          "Operation: " + operation + " not supported in service " + " portal");
    }

    ResolverContext resolverContext = new ResolverContext(request, getSite(siteKey));

    switch (portalOperation) {
      case forcedeviceclass:
        handleForceDeviceClass(resolverContext, response, formItems);
        break;
      case resetdeviceclass:
        handleResetDeviceClass(resolverContext, response);
        break;
      case forcelocale:
        handleForceLocale(resolverContext, response, formItems);
        break;
      case resetlocale:
        handleResetLocale(resolverContext, response);
        break;
    }

    redirectToPage(request, response, formItems);
  }
Esempio n. 20
0
  /**
   * trucate the string.
   *
   * @param strMethod set the method string trucated.
   * @return string of method.
   */
  private String trucateStringFromMethod(String strMethod) {

    final String strSet = "set";
    final String strGet = "get";
    final String strIs = "is";
    if (!strMethod.startsWith(strSet)
        && !strMethod.startsWith(strGet)
        && !strMethod.startsWith(strIs)) {
      return null;
    }

    int posAfterSet = strSet.length();
    if (strMethod.startsWith(strIs)) {
      posAfterSet = strIs.length();
    }

    String strMethodField = strMethod.substring(posAfterSet);
    String strFieldFirstLetter = strMethodField.substring(0, 1);
    String strReplace = StringUtils.lowerCase(strFieldFirstLetter);
    strMethodField = strMethodField.replaceFirst(strFieldFirstLetter, strReplace);

    return strMethodField;
  }
@UnitTest
public class MiniCartComponentControllerTest {

  private static final String COMPONENT_UID = "componentUid";
  private static final String TEST_COMPONENT_UID = "MiniCart";
  private static final String TEST_TYPE_CODE = "myTypeCode";
  private static final String TEST_TYPE_VIEW =
      ControllerConstants.Views.Cms.ComponentPrefix + StringUtils.lowerCase(TEST_TYPE_CODE);
  private static final Integer TOTAL_UNIT_COUNT = Integer.valueOf(1);
  private static final BigDecimal SUB_TOTAL_VALUE = BigDecimal.valueOf(100);
  private static final BigDecimal TOTAL_VALUE = BigDecimal.valueOf(200);
  private static final BigDecimal DELIVERY_VALUE = BigDecimal.valueOf(20);

  private MiniCartComponentController miniCartComponentController;
  private MiniCartComponentModel miniCartComponentModel;

  @Mock private DefaultCMSComponentService cmsComponentService;
  @Mock private HttpServletRequest request;
  @Mock private HttpServletResponse response;
  @Mock private CartFacade cartFacade;

  @Before
  public void setUp() throws CMSItemNotFoundException {
    MockitoAnnotations.initMocks(this);
    miniCartComponentController = new MiniCartComponentController();
    miniCartComponentController.setCmsComponentService(cmsComponentService);

    miniCartComponentModel = new MiniCartComponentModel();

    final PriceData subTotal = new PriceData();
    subTotal.setValue(SUB_TOTAL_VALUE);
    final PriceData totalPrice = new PriceData();
    totalPrice.setValue(TOTAL_VALUE);
    final PriceData deliveryCost = new PriceData();
    deliveryCost.setValue(DELIVERY_VALUE);

    final CartData cartData = new CartData();
    cartData.setSubTotal(subTotal);
    cartData.setTotalPrice(totalPrice);
    cartData.setDeliveryCost(deliveryCost);
    cartData.setTotalUnitCount(TOTAL_UNIT_COUNT);

    given(cartFacade.getMiniCart()).willReturn(cartData);
    given(request.getAttribute(COMPONENT_UID)).willReturn(TEST_COMPONENT_UID);

    ReflectionTestUtils.setField(
        miniCartComponentController, "cartFacade", cartFacade, CartFacade.class);
  }

  @Test
  public void testSubtotal() throws Exception {
    final ExtendedModelMap model = new ExtendedModelMap();
    miniCartComponentModel.setTotalDisplay(CartTotalDisplayType.SUBTOTAL);
    given(cmsComponentService.getSimpleCMSComponent(TEST_COMPONENT_UID))
        .willReturn(miniCartComponentModel);
    miniCartComponentController.handleGet(request, response, model);
    final PriceData priceData = (PriceData) model.get(MiniCartComponentController.SUB_TOTAL);
    Assert.assertEquals(SUB_TOTAL_VALUE, priceData.getValue());
  }

  @Test
  public void testTotal() throws Exception {
    final ExtendedModelMap model = new ExtendedModelMap();
    miniCartComponentModel.setTotalDisplay(CartTotalDisplayType.TOTAL);
    given(cmsComponentService.getSimpleCMSComponent(TEST_COMPONENT_UID))
        .willReturn(miniCartComponentModel);
    miniCartComponentController.handleGet(request, response, model);
    final PriceData priceData = (PriceData) model.get(MiniCartComponentController.TOTAL_PRICE);
    Assert.assertEquals(TOTAL_VALUE, priceData.getValue());
  }

  @Test
  public void testTotalWithoutDelivery() throws Exception {
    final ExtendedModelMap model = new ExtendedModelMap();
    miniCartComponentModel.setTotalDisplay(CartTotalDisplayType.TOTAL_WITHOUT_DELIVERY);
    given(cmsComponentService.getSimpleCMSComponent(TEST_COMPONENT_UID))
        .willReturn(miniCartComponentModel);
    miniCartComponentController.handleGet(request, response, model);
    final PriceData priceData =
        (PriceData) model.get(MiniCartComponentController.TOTAL_NO_DELIVERY);
    Assert.assertEquals(TOTAL_VALUE.subtract(DELIVERY_VALUE), priceData.getValue());
  }

  @Test
  public void testRenderComponent() throws Exception {
    final ExtendedModelMap model = new ExtendedModelMap();
    final String viewName =
        miniCartComponentController.handleComponent(
            request, response, model, miniCartComponentModel);
    Assert.assertEquals(TEST_TYPE_VIEW, viewName);
  }
}
 protected String prepareUserUid(final String userUid) {
   return StringUtils.lowerCase(userUid);
 }
 protected String getView(final T component) {
   // build a jsp response based on the component type
   return ControllerConstants.Views.Cms.ComponentPrefix
       + StringUtils.lowerCase(getTypeCode(component));
 }
  /**
   * Imports UploadBatch from tab/comma delimited File
   *
   * @param db database to import into
   * @param reader csv reader to load data from
   * @param defaults to set default values for each row
   * @param dbAction indicating wether to add,update,remove etc
   * @param missingValues indicating what value in the csv is treated as 'null' (e.g. "" or "NA")
   * @return number of elements imported
   */
  public int importCsv(
      final Database db,
      CsvReader reader,
      final Tuple defaults,
      final DatabaseAction dbAction,
      final String missingValues)
      throws DatabaseException, IOException, Exception {
    // cache for entities of which xrefs couldn't be resolved (e.g. if there
    // is a self-refence)
    // these entities can be updated with their xrefs in a second round when
    // all entities are in the database
    // final List<UploadBatch> uploadBatchsMissingRefs = new
    // ArrayList<UploadBatch>();

    final MutationService mutationService = new MutationService();
    mutationService.setDatabase(db);
    final UploadService uploadService = new UploadService();
    uploadService.setDatabase(db);

    final Submission submission = new Submission();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    submission.setDate(dateFormat.format(new Date()));
    submission.setReleasedate(dateFormat.format(new Date()));
    submission.setIdentifier("S" + new Date());
    if (db instanceof JDBCDatabase) {
      List<Integer> submitters = new ArrayList<Integer>();
      submitters.add(db.getLogin().getUserId());
      submission.setSubmitters_Id(submitters);
    } else if (db instanceof JpaDatabase) {
      List<MolgenisUser> submitters = new ArrayList<MolgenisUser>();
      submitters.add(db.findById(MolgenisUser.class, db.getLogin().getUserId()));
      // submission.setSubmitters(submitters);
    }
    db.add(submission);

    // cache for objects to be imported from file (in batch)
    // TODO: Danny: Use or loose
    /* final List<PatientSummaryVO> patientList = */ new ArrayList<PatientSummaryVO>(BATCH_SIZE);
    // wrapper to count
    final IntegerWrapper total = new IntegerWrapper(0);
    reader.setMissingValues(missingValues);

    Integer mutationIdentifier = uploadService.getMaxMutationIdentifier();
    Integer patientIdentifier = uploadService.getMaxPatientIdentifier();

    for (Tuple tuple : reader) {

      // parse object, setting defaults and values from file
      // if (lineNo > 5) return;
      PatientSummaryVO patientSummaryVO = new PatientSummaryVO();

      patientSummaryVO.setSubmissionDate(submission.getDate());

      patientSummaryVO.setPatientNumber(tuple.getString("Local patient number"));
      patientSummaryVO.setPatientGender(
          ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Gender")), "unknown"));
      patientSummaryVO.setPatientEthnicity(tuple.getString("Ethnicity"));
      patientSummaryVO.setPatientAge(ObjectUtils.toString(tuple.getString("Age"), "unknown"));
      patientSummaryVO.setPatientDeceased(
          ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Deceased")), "unknown"));
      patientSummaryVO.setPatientConsent(
          ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Signed consent")), "no"));

      patientSummaryVO.setVariantSummaryVOList(new ArrayList<MutationSummaryVO>());

      if (StringUtils.isNotEmpty(tuple.getString("cDNA change_1"))) {
        MutationUploadVO mutationUploadVO = new MutationUploadVO();
        mutationUploadVO.setGeneSymbol("COL7A1");
        mutationUploadVO.setMutation(new Mutation());
        mutationUploadVO.getMutation().setCdna_Notation("c." + tuple.getString("cDNA change_1"));
        mutationService.assignValuesFromNotation(mutationUploadVO);
        if (StringUtils.isNotEmpty(tuple.getString("Protein change_1")))
          mutationUploadVO.getMutation().setAa_Notation("p." + tuple.getString("Protein change_1"));
        if (StringUtils.isNotEmpty(tuple.getString("Consequence_1")))
          mutationUploadVO
              .getMutation()
              .setConsequence(ObjectUtils.toString(tuple.getString("Consequence_1"), ""));
        mutationUploadVO
            .getMutation()
            .setInheritance(
                ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Inheritance_1")), ""));

        mutationIdentifier = mutationIdentifier + 1;
        mutationUploadVO.getMutation().setIdentifier("M" + mutationIdentifier);
        mutationUploadVO.getMutation().setName("M" + mutationIdentifier);

        // Insert mutation if it does not exist already

        MutationSearchCriteriaVO criteria = new MutationSearchCriteriaVO();
        criteria.setVariation(mutationUploadVO.getMutation().getCdna_Notation());
        List<MutationSummaryVO> results = mutationService.findMutations(criteria);

        if (results.size() != 1) {
          uploadService.insert(mutationUploadVO);
          System.out.println(">>>Inserted mutation: " + mutationUploadVO.getMutation().toString());
        }
        MutationSummaryVO mutationSummaryVO = new MutationSummaryVO();
        mutationSummaryVO.setCdnaNotation(mutationUploadVO.getMutation().getCdna_Notation());

        patientSummaryVO.getVariantSummaryVOList().add(mutationSummaryVO);
      }

      // Second mutation can be 'NA' or 'unknown':
      // Leave xref == null and add remark in mutation2remark
      if (StringUtils.isNotEmpty(tuple.getString("cDNA change_2"))) {
        if (tuple.getString("cDNA change_2").equalsIgnoreCase("na"))
          patientSummaryVO.setVariantComment(tuple.getString("cDNA change_2").toUpperCase());
        else if (tuple.getString("cDNA change_2").equalsIgnoreCase("unknown"))
          patientSummaryVO.setVariantComment(tuple.getString("cDNA change_2").toUpperCase());
        else {
          MutationUploadVO mutationUploadVO = new MutationUploadVO();
          mutationUploadVO.setGeneSymbol("COL7A1");
          mutationUploadVO.setMutation(new Mutation());
          mutationUploadVO.getMutation().setCdna_Notation("c." + tuple.getString("cDNA change_2"));
          mutationService.assignValuesFromNotation(mutationUploadVO);
          if (StringUtils.isNotEmpty(tuple.getString("Protein change_2")))
            mutationUploadVO
                .getMutation()
                .setAa_Notation("p." + tuple.getString("Protein change_2"));
          if (StringUtils.isNotEmpty(tuple.getString("Consequence_2")))
            mutationUploadVO
                .getMutation()
                .setConsequence(ObjectUtils.toString(tuple.getString("Consequence_2"), ""));
          mutationUploadVO
              .getMutation()
              .setInheritance(
                  ObjectUtils.toString(
                      StringUtils.lowerCase(tuple.getString("Inheritance_2")), ""));

          mutationIdentifier = mutationIdentifier + 1;
          mutationUploadVO.getMutation().setIdentifier("M" + mutationIdentifier);
          mutationUploadVO.getMutation().setName("M" + mutationIdentifier);

          // Insert mutation if it does not exist already

          MutationSearchCriteriaVO criteria = new MutationSearchCriteriaVO();
          criteria.setVariation(mutationUploadVO.getMutation().getCdna_Notation());
          List<MutationSummaryVO> results = mutationService.findMutations(criteria);

          if (results.size() != 1) {
            uploadService.insert(mutationUploadVO);
            System.out.println(
                ">>>Inserted mutation: " + mutationUploadVO.getMutation().toString());
          }
          MutationSummaryVO mutationSummaryVO = new MutationSummaryVO();
          mutationSummaryVO.setCdnaNotation(mutationUploadVO.getMutation().getCdna_Notation());

          patientSummaryVO.getVariantSummaryVOList().add(mutationSummaryVO);
        }
      }

      patientSummaryVO.setPhenotypeMajor(
          StringUtils.upperCase(tuple.getString("Phenotype major type")));
      patientSummaryVO.setPhenotypeSub(StringUtils.lowerCase(tuple.getString("Phenotype Subtype")));

      // PhenotypeDetailsVO phenotypeDetailsVO = new PhenotypeDetailsVO();

      // patientSummaryVO.getPhenotypeDetails().setLocation(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Location")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setBlistering(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Blistering")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setHands(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Hands")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setFeet(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Feet")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setArms(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Arms")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setLegs(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Legs")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setProximal_Body_Flexures(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Proximal body flexures")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setTrunk(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Trunk")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setMucous_Membranes(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Mucosa")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setSkin_Atrophy(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Skin atrophy")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setMilia(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Milia")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setNail_Dystrophy(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Nail dystrophy")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setAlbopapuloid_Papules(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Albopapuloid papules")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setPruritic_Papules(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Pruritic papules")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setAlopecia(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Alopecia")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setSquamous_Cell_Carcinomas(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Squamous cell carcinoma(s)")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setRevertant_Skin_Patch(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Revertant skin patch(es)")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setMechanism(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Mechanism")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setFlexion_Contractures(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Flexion contractures")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setPseudosyndactyly_Hands(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Pseudosyndactyly (hands)")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setMicrostomia(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Microstomia")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setAnkyloglossia(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Ankyloglossia")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setDysphagia(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Swallowing difficulties/ dysphagia/ oesophagus strictures")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setGrowth_Retardation(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Growth retardation")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setAnemia(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Anaemia")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setRenal_Failure(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Renal failure")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setDilated_Cardiomyopathy(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Dilated cardiomyopathy")),
      // "unknown"));
      //
      // patientSummaryVO.getPhenotypeDetails().setColoboma(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Coloboma")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setCongenital_Heart_Defect(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Congenital heart defect")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setClp(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("C(L)P")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setChoanal_Anomaly(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Choanal anomaly")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setMental_Retardation(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Mental retardation")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setGrowth_Retardation(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Growth retardation")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setGenital_Hypoplasia(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Genital hypoplasia")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setExternal_Ear_Anomaly(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("External ear anomaly")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setSemicircular_Canal_Anomaly(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Semicircular canal anomaly")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setHearing_Loss(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("Hearing loss")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setTe_Anomaly(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("TE anomaly")),
      // "unknown"));
      // patientSummaryVO.getPhenotypeDetails().setCn_Dysfunction(ObjectUtils.toString(StringUtils.lowerCase(tuple.getString("CN dysfunction")),
      // "unknown"));

      // for (String field :
      // patientSummaryVO.getPhenotypeDetails().getFields(true))
      // {
      // if ("".equals(patientSummaryVO.getPhenotypeDetails().get(field)))
      // patientSummaryVO.getPhenotypeDetails().set(field, "unknown");
      // }
      // patientSummaryVO.getPhenotypeDetails().set(tuple.getString(""));

      if (tuple.getString("PubMed ID") != null && tuple.getString("Reference") != null) {
        List<PublicationVO> publicationVOs = new ArrayList<PublicationVO>();
        String[] pubmeds = tuple.getString("PubMed ID").split(";");
        String[] titles = tuple.getString("Reference").split(";");
        for (int i = 0; i < pubmeds.length; i++) {
          PublicationVO publicationVO = new PublicationVO();
          publicationVO.setPubmedId(pubmeds[i]);
          publicationVO.setName(titles[i]);
          publicationVO.setTitle(titles[i]);
          publicationVOs.add(publicationVO);
        }
        patientSummaryVO.setPublicationVOList(publicationVOs);
        patientSummaryVO.setPatientConsent("publication");
      }

      patientIdentifier = patientIdentifier + 1;
      patientSummaryVO.setPatientIdentifier("P" + patientIdentifier);
      patientSummaryVO.setPatientName("P" + patientIdentifier);

      patientSummaryVO.setObservedValueVOList(new ArrayList<ObservedValueVO>());

      ObservedValueVO observedValueVO;

      observedValueVO = new ObservedValueVO();
      observedValueVO.setFeatureName("LH7:2 Amount of type VII collagen");
      observedValueVO.setTargetName(patientSummaryVO.getPatientIdentifier());
      observedValueVO.setValue(ObjectUtils.toString(tuple.getString("IF LH7:2"), "unknown"));
      patientSummaryVO.getObservedValueVOList().add(observedValueVO);

      observedValueVO = new ObservedValueVO();
      observedValueVO.setFeatureName("IF Retention of type VII Collagen in basal cells");
      observedValueVO.setTargetName(patientSummaryVO.getPatientIdentifier());
      observedValueVO.setValue(
          ObjectUtils.toString(tuple.getString("IF Retention COLVII"), "unknown"));
      patientSummaryVO.getObservedValueVOList().add(observedValueVO);

      observedValueVO = new ObservedValueVO();
      observedValueVO.setFeatureName("Anchoring fibrils Number");
      observedValueVO.setTargetName(patientSummaryVO.getPatientIdentifier());
      observedValueVO.setValue(ObjectUtils.toString(tuple.getString("EM AF_no"), "unknown"));
      patientSummaryVO.getObservedValueVOList().add(observedValueVO);

      observedValueVO = new ObservedValueVO();
      observedValueVO.setFeatureName("Anchoring fibrils Ultrastructure");
      observedValueVO.setTargetName(patientSummaryVO.getPatientIdentifier());
      observedValueVO.setValue(ObjectUtils.toString(tuple.getString("EM AF_structure"), "unknown"));
      patientSummaryVO.getObservedValueVOList().add(observedValueVO);

      observedValueVO = new ObservedValueVO();
      observedValueVO.setFeatureName("EM Retention of type VII Collagen in basal cells");
      observedValueVO.setTargetName(patientSummaryVO.getPatientIdentifier());
      observedValueVO.setValue(
          ObjectUtils.toString(tuple.getString("EM_Retention COLVII"), "unknown"));
      patientSummaryVO.getObservedValueVOList().add(observedValueVO);

      for (int i = 34; ; i++) {
        System.out.println(">>>i==" + i);
        String colName = tuple.getColName(i);
        System.out.println(">>>colName==" + colName);

        if (colName == null) break;

        observedValueVO = new ObservedValueVO();
        observedValueVO.setFeatureName(colName);
        observedValueVO.setTargetName(patientSummaryVO.getPatientIdentifier());
        observedValueVO.setValue(ObjectUtils.toString(tuple.getString(colName), "unknown"));
        patientSummaryVO.getObservedValueVOList().add(observedValueVO);
      }

      uploadService.insert(patientSummaryVO);

      total.set(total.get() + 1);
      // patientList.add(patientSummaryVO);
      //
      // //add to db when batch size is reached
      // if(patientList.size() == BATCH_SIZE)
      // {
      // //resolve foreign keys and copy those entities that could not be
      // resolved to the missingRefs list
      // uploadBatchsMissingRefs.addAll(resolveForeignKeys(db,
      // uploadBatchList));
      //
      // //update objects in the database using xref_label defined
      // secondary key(s) 'id' defined in xref_label
      // db.update(uploadBatchList,dbAction, "id");
      //
      // //clear for next batch
      // uploadBatchList.clear();
      //
      // //keep count
      // total.set(total.get() + BATCH_SIZE);
      // }
    }

    // add remaining elements to the database
    // if(!uploadBatchList.isEmpty())
    // {
    // //resolve foreign keys, again keeping track of those entities that
    // could not be solved
    // uploadBatchsMissingRefs.addAll(resolveForeignKeys(db,
    // uploadBatchList));
    // //update objects in the database using xref_label defined secondary
    // key(s) 'id' defined in xref_label
    // db.update(uploadBatchList,dbAction, "id");
    // }
    //
    // //second import round, try to resolve FK's for entities again as they
    // might have referred to entities in the imported list
    // List<UploadBatch> uploadBatchsStillMissingRefs =
    // resolveForeignKeys(db, uploadBatchsMissingRefs);
    //
    // //if there are still missing references, throw error and rollback
    // if(uploadBatchsStillMissingRefs.size() > 0){
    // throw new
    // Exception("Import of 'UploadBatch' objects failed: attempting to resolve in-list references,
    // but there are still UploadBatchs referring to UploadBatchs that are neither in the database
    // nor in the list of to-be imported UploadBatchs. (the first one being:
    // "+uploadBatchsStillMissingRefs.get(0)+")");
    // }
    // //else update the entities in the database with the found references
    // and return total
    // else
    // {
    // db.update(uploadBatchsMissingRefs,DatabaseAction.UPDATE, "id");
    //
    // //output count
    // total.set(total.get() + uploadBatchList.size());
    // logger.info("imported "+total.get()+" uploadBatch from CSV");
    //
    // return total.get();
    // }

    return total.get();
  }
 public String getMode() {
   return StringUtils.lowerCase(this.toString());
 }
 @Override
 public boolean matches(LogData logData) {
   return StringUtils.contains(StringUtils.lowerCase(logData.getMessage()), searchChar);
 }
 @Override
 protected String getView(final PurchasedCategorySuggestionComponentModel component) {
   return ControllerConstants.Views.Cms.ComponentPrefix
       + StringUtils.lowerCase(SimpleSuggestionComponentModel._TYPECODE);
 }
Esempio n. 28
0
 private <T> T getBean(Class<T> aClass) {
   String name = aClass.getSimpleName();
   name = StringUtils.lowerCase(name.substring(0, 1)) + name.substring(1);
   return (T) applicationContext.getBean(name);
 }
 private String getLibraryName(HtmlLibrary library) {
   return StringUtils.replace(
       library.getName(true), "min", StringUtils.lowerCase(this.optimization.name()));
 }
Esempio n. 30
0
    private void doPreparedStatement(
        PreparedStatement ps, DbDialect dbDialect, LobCreator lobCreator, EventData data)
        throws SQLException {
      EventType type = data.getEventType();
      // 注意insert/update语句对应的字段数序都是将主键排在后面
      List<EventColumn> columns = new ArrayList<EventColumn>();
      if (type.isInsert()) {
        columns.addAll(data.getColumns()); // insert为所有字段
        columns.addAll(data.getKeys());
      } else if (type.isDelete()) {
        columns.addAll(data.getKeys());
      } else if (type.isUpdate()) {
        boolean existOldKeys = !CollectionUtils.isEmpty(data.getOldKeys());
        columns.addAll(data.getUpdatedColumns()); // 只更新带有isUpdate=true的字段
        columns.addAll(data.getKeys());
        if (existOldKeys) {
          columns.addAll(data.getOldKeys());
        }
      }
      for (int i = 0; i < columns.size(); i++) {
        int paramIndex = i + 1;
        EventColumn column = columns.get(i);
        int sqlType = column.getColumnType();

        // 获取一下当前字段名的数据是否必填
        Table table = dbDialect.findTable(data.getSchemaName(), data.getTableName());
        Map<String, Boolean> isRequiredMap = new HashMap<String, Boolean>();
        for (Column tableColumn : table.getColumns()) {
          isRequiredMap.put(StringUtils.lowerCase(tableColumn.getName()), tableColumn.isRequired());
        }

        Boolean isRequired = isRequiredMap.get(StringUtils.lowerCase(column.getColumnName()));
        if (isRequired == null) {
          throw new ClaveException(
              String.format(
                  "column name %s is not found in Table[%s]",
                  column.getColumnName(), table.toString()));
        }

        Object param =
            SqlUtils.stringToSqlValue(
                column.getColumnValue(), sqlType, isRequired, dbDialect.isEmptyStringNulled());
        try {
          switch (sqlType) {
            case Types.CLOB:
              lobCreator.setClobAsString(ps, paramIndex, (String) param);
              break;

            case Types.BLOB:
              lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
              break;

            default:
              StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
              break;
          }
        } catch (SQLException ex) {
          logger.error(
              "## SetParam error , [table={}, sqltype={}, value={}]",
              new Object[] {data.getSchemaName() + "." + data.getTableName(), sqlType, param});
          throw ex;
        }
      }
    }