コード例 #1
0
  private Map<String, Object> mergeCollectionItemMetaData(Map<String, Object> content) {
    Object data = content.get(META_DATA);
    if (data != null) {
      Map<String, Object> metaData =
          JsonDeserializer.deserialize(
              String.valueOf(data), new TypeReference<Map<String, Object>>() {});
      content.putAll(metaData);
    }
    Map<String, Object> resourceFormat = new HashMap<String, Object>();
    resourceFormat.put(VALUE, content.get(VALUE));
    resourceFormat.put(DISPLAY_NAME, content.get(DISPLAY_NAME));
    content.put(RESOURCEFORMAT, resourceFormat);
    Object ratingAverage = content.get(AVERAGE);
    String typeName = (String) content.get(RESOURCE_TYPE);
    Map<String, Object> resourceType = new HashMap<String, Object>();
    resourceType.put(NAME, typeName);
    content.put(RESOURCE_TYPE, resourceType);
    if (ratingAverage != null) {
      Map<String, Object> rating = new HashMap<String, Object>();
      rating.put(AVERAGE, content.get(AVERAGE));
      rating.put(COUNT, content.get(COUNT));
      content.put(RATING, rating);
    }

    Object thumbnail = content.get(THUMBNAIL);
    if (thumbnail != null) {
      StringBuilder imagePath = new StringBuilder();
      imagePath.append(content.get(FOLDER)).append(thumbnail);
      content.put(THUMBNAILS, GooruImageUtil.getThumbnails(imagePath.toString()));
    }
    if (typeName.equalsIgnoreCase(ResourceType.Type.ASSESSMENT_QUESTION.getType())) {
      // To-Do, need fix later, by getting answer and hints details
      // without querying the assessment object
      String gooruOid = (String) content.get(GOORU_OID);
      AssessmentQuestion assessmentQuestion = this.getQuestionService().getQuestion(gooruOid);
      if (assessmentQuestion != null && !assessmentQuestion.isQuestionNewGen()) {
        content.put(ANSWERS, assessmentQuestion.getAnswers());
        content.put(HINTS, assessmentQuestion.getHints());
      } else {
        String json = getMongoQuestionsService().getQuestionByIdWithJsonAdjustments(gooruOid);
        if (json != null) {
          content.putAll(
              JsonDeserializer.deserialize(json, new TypeReference<Map<String, Object>>() {}));
        }
      }
    }
    content.put(USER, setUser(content.get(GOORU_UID), content.get(USER_NAME)));
    content.put(ASSET_URI, ConfigProperties.getBaseRepoUrl());
    content.remove(THUMBNAIL);
    content.remove(META_DATA);
    content.remove(VALUE);
    content.remove(DISPLAY_NAME);
    content.remove(AVERAGE);
    content.remove(COUNT);
    content.remove(GOORU_UID);
    content.remove(USER_NAME);
    return content;
  }
コード例 #2
0
 @Override
 @Transactional(
     readOnly = false,
     propagation = Propagation.REQUIRED,
     rollbackFor = Exception.class)
 public CollectionItem createQuestion(String collectionId, String data, User user) {
   Collection collection = getCollectionDao().getCollectionByType(collectionId, COLLECTION_TYPES);
   rejectIfNull(collection, GL0056, 404, COLLECTION);
   AssessmentQuestion question = getQuestionService().createQuestion(data, user);
   CollectionItem collectionItem = new CollectionItem();
   collectionItem.setItemType(ADDED);
   collectionItem = createCollectionItem(collectionItem, collection, question, user);
   getCollectionEventLog()
       .collectionItemEventLog(
           collectionId, collectionItem, user.getPartyUid(), QUESTION, data, ADD);
   collectionItem.setQuestion(question);
   collectionItem.setTitle(question.getTitle());
   updateCollectionMetaDataSummary(collection.getContentId(), QUESTION, ADD);
   Map<String, Object> metaData = generateQuestionMetaData(question, question, user);
   createContentMeta(question, metaData);
   return collectionItem;
 }