private void createUpdateElisaList(List<AnalysisItem> resultItems) {

    for (AnalysisItem resultItem : resultItems) {

      if (resultItem.getIsAccepted()) {

        List<Analysis> acceptedAnalysisList = createAnalysisFromElisaAnalysisItem(resultItem);

        for (Analysis analysis : acceptedAnalysisList) {
          analysis.setStatusId(StatusService.getInstance().getStatusID(AnalysisStatus.Finalized));
          analysisUpdateList.add(analysis);
        }
      }

      if (resultItem.getIsRejected()) {
        List<Analysis> rejectedAnalysisList = createAnalysisFromElisaAnalysisItem(resultItem);

        for (Analysis analysis : rejectedAnalysisList) {
          analysis.setStatusId(
              StatusService.getInstance().getStatusID(AnalysisStatus.BiologistRejected));
          analysisUpdateList.add(analysis);
        }
      }
    }
  }
 private void setSampleFinishedStatuses() {
   sampleFinishedStatus = new ArrayList<Integer>();
   sampleFinishedStatus.add(
       Integer.parseInt(StatusService.getInstance().getStatusID(AnalysisStatus.Finalized)));
   sampleFinishedStatus.add(
       Integer.parseInt(StatusService.getInstance().getStatusID(AnalysisStatus.Canceled)));
   sampleFinishedStatus.add(
       Integer.parseInt(
           StatusService.getInstance().getStatusID(AnalysisStatus.NonConforming_depricated)));
 }
  private void checkIfSamplesFinished(List<AnalysisItem> resultItemList) {
    sampleUpdateList = new ArrayList<Sample>();

    String currentSampleId = "";
    boolean sampleFinished = true;

    for (AnalysisItem analysisItem : resultItemList) {

      String analysisSampleId =
          sampleDAO.getSampleByAccessionNumber(analysisItem.getAccessionNumber()).getId();
      if (!analysisSampleId.equals(currentSampleId)) {

        currentSampleId = analysisSampleId;

        List<Analysis> analysisList = analysisDAO.getAnalysesBySampleId(currentSampleId);

        for (Analysis analysis : analysisList) {
          if (!sampleFinishedStatus.contains(Integer.parseInt(analysis.getStatusId()))) {
            sampleFinished = false;
            break;
          }
        }

        if (sampleFinished) {
          Sample sample = new Sample();
          sample.setId(currentSampleId);
          sampleDAO.getData(sample);
          sample.setStatusId(StatusService.getInstance().getStatusID(OrderStatus.Finished));
          sampleUpdateList.add(sample);
        }

        sampleFinished = true;
      }
    }
  }
Example #4
0
  @RequestMapping(value = PREFIX_API_1_COMMENTS + "destroy", method = RequestMethod.POST)
  @ResponseBody
  public Object destroy(@RequestParam(value = "id") String id) {
    Comment comment = commentService.getComment(id);
    if (comment == null) {
      return ErrorDto.badRequest(String.format("评论不存在(id=%s)", id));
    }

    boolean permission = false;
    // 评论作者有权限删除
    if (comment.getUserId().equals(accountService.getCurrentUserId())) {
      permission = true;
    }

    // 帖子作者有权限删除
    if (!permission) {
      Post post = statusService.getPost(comment.getPostId());
      if (accountService.getCurrentUserId().equals(post.getUserId())) {
        permission = true;
      }
    }

    if (permission) {
      commentService.deleteComment(comment);
      return commentService.toBasicCommentDto(comment);
    } else {
      return ErrorDto.forbidden();
    }
  }
  private void createUpdateList(List<AnalysisItem> analysisItems, boolean areListeners) {

    List<String> analysisIdList = new ArrayList<String>();

    for (AnalysisItem analysisItem : analysisItems) {
      if (!analysisItem.isReadOnly() && analysisItemWillBeUpdated(analysisItem)) {

        AnalysisService analysisService = new AnalysisService(analysisItem.getAnalysisId());
        Analysis analysis = analysisService.getAnalysis();
        NoteService noteService = new NoteService(analysis);

        analysis.setSysUserId(currentUserId);

        if (!analysisIdList.contains(analysis.getId())) {

          if (analysisItem.getIsAccepted()) {
            analysis.setStatusId(StatusService.getInstance().getStatusID(AnalysisStatus.Finalized));
            analysis.setReleasedDate(new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
            analysisIdList.add(analysis.getId());
            analysisUpdateList.add(analysis);
          }

          if (analysisItem.getIsRejected()) {
            analysis.setStatusId(
                StatusService.getInstance().getStatusID(AnalysisStatus.BiologistRejected));
            analysisIdList.add(analysis.getId());
            analysisUpdateList.add(analysis);
          }
        }

        createNeededNotes(analysisItem, noteService);

        if (areResults(analysisItem)) {
          List<Result> results =
              createResultFromAnalysisItem(analysisItem, analysisService, noteService);
          for (Result result : results) {
            resultUpdateList.add(result);

            if (areListeners) {
              addResultSets(analysis, result);
            }
          }
        }
      }
    }
  }
 public synchronized void registerDeploymentEvent(
     String deploymentPaaSId, String deploymentId, DeploymentStatus deploymentStatus) {
   statusService.registerDeploymentEvent(deploymentPaaSId, deploymentStatus);
   paaSDeploymentIdToAlienDeploymentIdMapping.put(deploymentPaaSId, deploymentId);
   alienDeploymentIdToPaaSDeploymentIdMapping.put(deploymentId, deploymentPaaSId);
   PaaSDeploymentStatusMonitorEvent deploymentStatusMonitorEvent =
       new PaaSDeploymentStatusMonitorEvent();
   deploymentStatusMonitorEvent.setDeploymentStatus(deploymentStatus);
   deploymentStatusMonitorEvent.setDeploymentId(deploymentId);
   internalProviderEventsQueue.add(deploymentStatusMonitorEvent);
 }
  // test null value in rows doesn't throw
  public void testTextNull() throws Exception {
    MockStatusAccessor statusAccessor =
        MockStatusAccessor.generateStatusAccessor(colArray1, rowArrayWithNulls);
    statSvc.registerStatusAccessor("testtbl", statusAccessor);

    WebResponse resp = getTable("testtbl", true);
    log.debug(resp.getText());

    List lines = getLines(resp);
    assertEqualTables(tableWithNulls, lines);
  }
  // test special (non-string) key in row doesn't throw
  public void testTextNonStringKey() throws Exception {
    MockStatusAccessor statusAccessor = new MockStatusAccessor();
    List cols = ListUtil.list("foo", StatusTable.ROW_SEPARATOR);
    statusAccessor.setRows(MockStatusAccessor.makeRowsFrom(cols, rowArray1), null);
    statusAccessor.setColumnDescriptors(
        MockStatusAccessor.makeColumnDescriptorsFrom(colArray1), null);

    statSvc.registerStatusAccessor("testtbl", statusAccessor);

    WebResponse resp = getTable("testtbl", true);
    log.debug(resp.getText());
  }
Example #9
0
  private Object createComment(
      String text,
      String replyCommentId,
      String postId,
      FileInfo videoFileInfo,
      FileInfo imageFileInfo,
      FileInfo audioFileInfo) {

    Comment comment = new Comment();
    comment.setUserId(accountService.getCurrentUserId());
    comment.setText(text);
    // 回复Comment
    if (StringUtils.isNotBlank(replyCommentId)) {
      Comment replyComment = commentService.getComment(replyCommentId);
      if (replyComment == null) {
        return ErrorDto.badRequest(String.format("replyCommentId[%s]无效", replyCommentId));
      }
      comment.setReplyCommentId(replyCommentId);
      comment.setReplyCommentUserId(replyComment.getUserId());
      comment.setPostId(replyComment.getPostId());
    }
    // 回复Post
    else {
      Post post = statusService.getPost(postId);
      if (post == null) {
        return ErrorDto.badRequest(String.format("postId[%s]不存在", postId));
      }

      if (!post.isPublic()) {
        return ErrorDto.badRequest("不能评论非所有人可见的视频");
      }

      // 回复原始贴
      if (post.getOriginPostId() == null) {
        comment.setPostId(postId);
      }
      // 回复转发贴,归结到原始贴上
      else {
        comment.setPostId(post.getOriginPostId());
      }
    }

    comment = commentService.create(comment, videoFileInfo, imageFileInfo, audioFileInfo);
    return commentService.toCommentDto(comment);
  }
Example #10
0
  public void testText() throws Exception {
    MockStatusAccessor statusAccessor =
        MockStatusAccessor.generateStatusAccessor(colArray1, rowArray1);
    statusAccessor.setTitle("testtbl", null);
    statSvc.registerStatusAccessor("testtbl", statusAccessor);

    WebResponse resp = getTable("testtbl", true);
    assertResponseOk(resp);
    assertEquals("Content type", "text/plain", resp.getContentType());
    log.debug(resp.getText());
    List lines = getLines(resp);
    assertEquals(rowArray1.length + 3, lines.size());
    Map row0 = getRow((String) lines.get(0));
    assertEquals("2.4.6.8", row0.get("host"));

    Map row2 = getRow((String) lines.get(2));
    assertEquals("testtbl", row2.get("table"));

    assertEqualTables(table1, lines);
  }
 private AbstractMonitorEvent toAlienEvent(Event cloudifyEvent) {
   AbstractMonitorEvent alienEvent;
   switch (cloudifyEvent.getEventType()) {
     case EventType.WORKFLOW_SUCCEEDED:
       PaaSDeploymentStatusMonitorEvent succeededStatusEvent =
           new PaaSDeploymentStatusMonitorEvent();
       if (Workflow.INSTALL.equals(cloudifyEvent.getContext().getWorkflowId())) {
         succeededStatusEvent.setDeploymentStatus(DeploymentStatus.DEPLOYED);
       } else if (Workflow.DELETE_DEPLOYMENT_ENVIRONMENT.equals(
           cloudifyEvent.getContext().getWorkflowId())) {
         succeededStatusEvent.setDeploymentStatus(DeploymentStatus.UNDEPLOYED);
       } else {
         return null;
       }
       alienEvent = succeededStatusEvent;
       break;
     case EventType.WORKFLOW_FAILED:
       PaaSDeploymentStatusMonitorEvent failedStatusEvent = new PaaSDeploymentStatusMonitorEvent();
       failedStatusEvent.setDeploymentStatus(DeploymentStatus.FAILURE);
       alienEvent = failedStatusEvent;
       break;
     case EventType.TASK_SUCCEEDED:
       if (Workflow.DELETE_DEPLOYMENT_ENVIRONMENT.equals(
               cloudifyEvent.getContext().getWorkflowId())
           && "riemann_controller.tasks.delete".equals(cloudifyEvent.getContext().getTaskName())) {
         PaaSDeploymentStatusMonitorEvent undeployedEvent = new PaaSDeploymentStatusMonitorEvent();
         undeployedEvent.setDeploymentStatus(DeploymentStatus.UNDEPLOYED);
         alienEvent = undeployedEvent;
       } else {
         String newInstanceState =
             CloudifyLifeCycle.getSucceededInstanceState(
                 cloudifyEvent.getContext().getOperation());
         if (newInstanceState == null) {
           return null;
         }
         PaaSInstanceStateMonitorEvent instanceTaskStartedEvent =
             new PaaSInstanceStateMonitorEvent();
         instanceTaskStartedEvent.setInstanceId(cloudifyEvent.getContext().getNodeId());
         instanceTaskStartedEvent.setNodeTemplateId(cloudifyEvent.getContext().getNodeName());
         instanceTaskStartedEvent.setInstanceState(newInstanceState);
         instanceTaskStartedEvent.setInstanceStatus(
             statusService.getInstanceStatusFromState(newInstanceState));
         alienEvent = instanceTaskStartedEvent;
       }
       break;
     case EventType.A4C_PERSISTENT_EVENT:
       String persistentCloudifyEvent = cloudifyEvent.getMessage().getText();
       ObjectMapper objectMapper = new ObjectMapper();
       objectMapper.setPropertyNamingStrategy(
           PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
       try {
         EventAlienPersistent eventAlienPersistent =
             objectMapper.readValue(persistentCloudifyEvent, EventAlienPersistent.class);
         // query API
         // TODO make that Async
         NodeInstance instance = nodeInstanceClient.read(cloudifyEvent.getContext().getNodeId());
         String attributeValue =
             (String)
                 instance
                     .getRuntimeProperties()
                     .get(eventAlienPersistent.getPersistentResourceId());
         alienEvent =
             new PaaSInstancePersistentResourceMonitorEvent(
                 cloudifyEvent.getContext().getNodeName(),
                 cloudifyEvent.getContext().getNodeId(),
                 eventAlienPersistent.getPersistentAlienAttribute(),
                 attributeValue);
       } catch (IOException e) {
         return null;
       }
       break;
     case EventType.A4C_WORKFLOW_STARTED:
       String wfCloudifyEvent = cloudifyEvent.getMessage().getText();
       objectMapper = new ObjectMapper();
       objectMapper.setPropertyNamingStrategy(
           PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
       try {
         EventAlienWorkflowStarted eventAlienWorkflowStarted =
             objectMapper.readValue(wfCloudifyEvent, EventAlienWorkflowStarted.class);
         PaaSWorkflowStepMonitorEvent e = new PaaSWorkflowStepMonitorEvent();
         PaaSWorkflowMonitorEvent pwme = new PaaSWorkflowMonitorEvent();
         pwme.setExecutionId(cloudifyEvent.getContext().getExecutionId());
         pwme.setWorkflowId(eventAlienWorkflowStarted.getWorkflowName());
         pwme.setSubworkflow(eventAlienWorkflowStarted.getSubworkflow());
         alienEvent = pwme;
       } catch (IOException e) {
         return null;
       }
       break;
     case EventType.A4C_WORKFLOW_EVENT:
       wfCloudifyEvent = cloudifyEvent.getMessage().getText();
       objectMapper = new ObjectMapper();
       objectMapper.setPropertyNamingStrategy(
           PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
       try {
         EventAlienWorkflow eventAlienPersistent =
             objectMapper.readValue(wfCloudifyEvent, EventAlienWorkflow.class);
         PaaSWorkflowStepMonitorEvent e = new PaaSWorkflowStepMonitorEvent();
         e.setNodeId(cloudifyEvent.getContext().getNodeName());
         e.setInstanceId(cloudifyEvent.getContext().getNodeId());
         e.setStepId(eventAlienPersistent.getStepId());
         e.setStage(eventAlienPersistent.getStage());
         String workflowId = cloudifyEvent.getContext().getWorkflowId();
         e.setExecutionId(cloudifyEvent.getContext().getExecutionId());
         if (workflowId.startsWith(Workflow.A4C_PREFIX)) {
           workflowId = workflowId.substring(Workflow.A4C_PREFIX.length());
         }
         e.setWorkflowId(cloudifyEvent.getContext().getWorkflowId());
         alienEvent = e;
       } catch (IOException e) {
         return null;
       }
       break;
     default:
       return null;
   }
   alienEvent.setDate(
       DatatypeConverter.parseDateTime(cloudifyEvent.getTimestamp()).getTimeInMillis());
   String alienDeploymentId =
       paaSDeploymentIdToAlienDeploymentIdMapping.get(
           cloudifyEvent.getContext().getDeploymentId());
   if (alienDeploymentId == null) {
     if (log.isDebugEnabled()) {
       log.debug(
           "Alien deployment id is not found for paaS deployment {}, must ignore this event {}",
           cloudifyEvent.getContext().getDeploymentId(),
           cloudifyEvent);
     }
     return null;
   }
   alienEvent.setDeploymentId(alienDeploymentId);
   return alienEvent;
 }
Example #12
0
  // TODO 优化代码,视频评论和文字评论大部分重复
  @RequestMapping(value = PREFIX_API_1_COMMENTS + "create", method = RequestMethod.POST)
  @ResponseBody
  public Object create(
      @RequestParam(value = "text") String text,
      @RequestParam(value = "postId", required = false) String postId,
      @RequestParam(value = "replyCommentId", required = false) String replyCommentId) {

    try {
      logger.debug("正在发布文字评论:");
      logger.debug("            text : {}", text);
      logger.debug("          postId : {}", postId);
      logger.debug("  replyCommentId : {}", replyCommentId);

      if (StringUtils.isBlank(postId) && StringUtils.isBlank(replyCommentId)) {
        return ErrorDto.badRequest("参数postId和replyCommentId不能都为空");
      }

      Comment comment = new Comment();

      // 回复Comment
      if (StringUtils.isNotBlank(replyCommentId)) {
        Comment replyComment = commentService.getComment(replyCommentId);
        if (replyComment == null) {
          return ErrorDto.badRequest(String.format("replyCommentId[%s]无效", replyCommentId));
        }
        comment.setReplyCommentId(replyCommentId);
        comment.setReplyCommentUserId(replyComment.getUserId());
        comment.setPostId(replyComment.getPostId());
        // TODO 存被回复者screenName以提高性能
      }
      // 回复Post
      else {
        Post post = statusService.getPost(postId);

        if (post == null) {
          return ErrorDto.badRequest(String.format("postId[%s]不存在", postId));
        }

        if (!post.isPublic()) {
          return ErrorDto.badRequest("不能评论非所有人可见的视频");
        }

        if (post.getOriginPostId() == null) {
          comment.setPostId(postId);
        } else {
          comment.setPostId(post.getOriginPostId());
        }
      }

      comment.setUserId(accountService.getCurrentUserId());
      comment.setText(text);

      comment = commentService.create(comment, null, null, null);
      return commentService.toCommentDto(comment);

    } catch (DuplicateException e) {
      return ErrorDto.duplicate();
    } catch (Exception e) {
      logger.info("发布评论失败", e);
      return ErrorDto.internalServerError(e.getMessage());
    }
  }