コード例 #1
0
 @Override
 public ModelNominalLabelDTO editModelNominalLabel(ModelNominalLabelDTO modelNominalLabel)
     throws PropertyNotSetException {
   logger.info(
       "Received request for: "
           + modelNominalLabel.getIdDTO().getNominalLabelId()
           + ":"
           + modelNominalLabel.getIdDTO().getModelId());
   try {
     ModelNominalLabel label = modelNominalLabel.toEntity();
     ModelNominalLabel oldLabel =
         getByCriteria(Restrictions.eq("id", modelNominalLabel.getIdDTO().toEntity()));
     if (oldLabel != null) {
       oldLabel = em.merge(label);
       return (oldLabel != null) ? new ModelNominalLabelDTO(oldLabel) : null;
     } else {
       throw new RuntimeException("Not found");
     }
   } catch (Exception e) {
     logger.error(
         "Exception in merging/updating nominalLabel: "
             + modelNominalLabel.getIdDTO().getNominalLabelId(),
         e);
   }
   return null;
 }
コード例 #2
0
 @Override
 public Integer deleteModelNominalLabel(ModelNominalLabelDTO modelNominalLabel)
     throws PropertyNotSetException {
   if (modelNominalLabel != null) {
     ModelNominalLabel managed = em.merge(modelNominalLabel.toEntity());
     em.remove(managed);
     return 1;
   }
   return 0;
 }
コード例 #3
0
 @Override
 public ModelNominalLabelDTO addModelNominalLabel(ModelNominalLabelDTO modelNominalLabel) {
   try {
     ModelNominalLabel modelLabel = modelNominalLabel.toEntity();
     em.persist(modelLabel);
     em.flush();
     em.refresh(modelLabel);
     return new ModelNominalLabelDTO(modelLabel);
   } catch (Exception e) {
     logger.error("Error in addModelNominalLabel.", e);
     return null;
   }
 }
コード例 #4
0
  @Override
  public List<ModelNominalLabelDTO> getAllModelNominalLabelsByModelID(
      Long modelID, String crisisCode) {
    List<ModelNominalLabelDTO> dtoList = new ArrayList<ModelNominalLabelDTO>();
    ;
    List<ModelNominalLabel> modelNominalLabelList = new ArrayList<ModelNominalLabel>();

    Model model = modelEJB.getById(modelID);
    if (model != null) {
      logger.info(
          "Model is not NULL in getAllModelNominalLabelsByModelID for modelID = "
              + modelID
              + ",crisis code = "
              + crisisCode);
      Hibernate.initialize(model.getModelFamily());

      try {
        Boolean modelStatus = model.getModelFamily().isIsActive(); // getting model status
        ModelFamily modelFamily = model.getModelFamily();
        Hibernate.initialize(modelFamily.getNominalAttribute());
        Long nominalAttributeId = modelFamily.getNominalAttribute().getNominalAttributeId();
        // Long nominalAttributeId =
        // model.getModelFamily().getNominalAttribute().getNominalAttributeId();

        modelNominalLabelList = this.getAllByCriteria(Restrictions.eq("id.modelId", modelID));
        logger.info(
            "modelNominalLabellist size = "
                + (modelNominalLabelList != null ? modelNominalLabelList.size() : "null"));

        for (ModelNominalLabel labelEntity : modelNominalLabelList) {

          // Getting training examples for each label
          int trainingSet = 0;
          NominalLabel nominalLabel = labelEntity.getNominalLabel();

          if (nominalLabel != null
              && !nominalLabel.getNominalLabelCode().equalsIgnoreCase("null")) {
            try {
              trainingSet =
                  documentEJB.getDocumentCountForNominalLabelAndCrisis(
                      nominalLabel.getNominalLabelId(), crisisCode);
            } catch (Exception e) {
              // TODO Auto-generated catch block
              logger.error("Error in getDocumentCollectionWithNominalLabelData.", e);
            }
          }
          // Deep copying modelNominalLabel to ModelNominalLabelDTO
          Hibernate.initialize(labelEntity.getModel());
          Hibernate.initialize(labelEntity.getNominalLabel());

          ModelNominalLabelDTO dto = new ModelNominalLabelDTO(labelEntity);
          dto.setModelStatus(modelStatus == true ? "RUNNING" : "NOT RUNNING");
          dto.setNominalAttributeId(nominalAttributeId);
          dto.setTrainingDocuments(trainingSet);
          dtoList.add(dto);
        }
      } catch (Exception e) {
        logger.error("Exception occured in getAllModelNominalLabelsByModelID \n\n", e);
        return null;
      }
    }
    return dtoList;
  }
コード例 #5
0
 @Override
 public void saveModelNominalLabel(ModelNominalLabelDTO modelNominalLabel)
     throws PropertyNotSetException {
   save(modelNominalLabel.toEntity());
 }