public Future<Void> createActivity( UserId userId, GroupId groupId, String appId, Set<String> fields, Activity activity, SecurityToken token) throws ProtocolException { Session hs = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tran = null; try { Long startTime = new Date().getTime(); tran = hs.beginTransaction(); // check if the person exists String user = userId.getUserId(token); Person person = (Person) hs.get(Person.class, user); if (person == null) throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "Person does not exist"); if (activity.getStreamFaviconUrl() != null || activity.getStreamSourceUrl() != null || activity.getStreamTitle() != null || activity.getStreamUrl() != null) throw new ProtocolException( HttpServletResponse.SC_BAD_REQUEST, "Creating activity with stream params"); // create Activity com.skt.opensocial.persistence.Activity activityDB = this.setActivityDBFromActivity(person, appId, activity); activityDB.setPerson(person); // auto increment "id" is the activity id Integer newId = (Integer) hs.save(activityDB); activityDB.setActivityId(newId.toString()); // set up the posted time Long endTime = new Date().getTime(); activityDB.setPostedTime(new Double(endTime - startTime)); hs.saveOrUpdate(activityDB); // **** insert activity with mediaItems and templateParams separately ****// // create MediaItems of the Activity List<MediaItem> items = activity.getMediaItems(); if (items != null) { for (MediaItem item : items) { com.skt.opensocial.persistence.ActivityMediaItem mediaItemDB = this.setMediaItemDBFromMediaItem(user, activityDB.getActivityId(), item); hs.saveOrUpdate(mediaItemDB); } } // create TemplateParams of the activity Map<String, String> params = activity.getTemplateParams(); if (params != null) { Set<String> keys = params.keySet(); for (String key : keys) { com.skt.opensocial.persistence.ActivityTemplateParam templateParamDB = this.setTemplateParamDBFromTemplateParma( user, activityDB.getActivityId(), key, params.get(key)); hs.saveOrUpdate(templateParamDB); } } tran.commit(); return ImmediateFuture.newInstance(null); } catch (HibernateException e) { if (tran != null) tran.rollback(); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e); } }