Android Open Source - innovativeproject-meetingdataexchange Meetings






From Project

Back to project page innovativeproject-meetingdataexchange.

License

The source code is released under:

MIT License

If you think the Android project innovativeproject-meetingdataexchange listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package controllers;
// ww w.  jav  a  2s  .co  m
import static models.Tables.*;

import java.io.File;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.sql.Timestamp;
import java.util.Iterator;

import models.DbSingleton;

import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record8;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;

public class Meetings extends Controller {
  
  public static Result createNew(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");
    
    String login = json.findPath("login").textValue();
    String sid = json.findPath("sid").textValue();
    String title = json.findPath("title").textValue();
    String topic = json.findPath("topic").textValue();
    String abilityToSendFiles = json.findPath("abilityToSendFiles").textValue();
    
    return ok(web_createNew(login, sid, title, topic, abilityToSendFiles));
  }
  
  public static ObjectNode web_createNew(String login, String sid, String title, String topic, String abilityToSendFiles){
    if(login==null || title==null || topic==null || abilityToSendFiles==null || sid==null)
      return errorObject("incorrect data");
    
    boolean permit;
    if(!abilityToSendFiles.equals("true") && !abilityToSendFiles.equals("false"))
      return errorObject("incorrect data");
    else if (abilityToSendFiles.equals("true"))
      permit = true;
    else
      permit = false;
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    
    java.util.Date date= new java.util.Date();
    String hash = new BigInteger(130, new SecureRandom()).toString(32);
    hash = hash.substring(1,6);
    Record record = DbSingleton.getInstance().getDsl()
        .insertInto(MEETING,
            MEETING.TITLE, MEETING.TOPIC, MEETING.STARTTIME, MEETING.ABILITYTOSENDFILES, 
            MEETING.AUTHORLOGIN, MEETING.ACCESSCODE)
        .values(title, topic, new Timestamp(date.getTime()), permit, login, hash)
        .returning(MEETING.ID)
        .fetchOne();
    
    int meetingId = record.getValue(MEETING.ID);
    Timestamp ts = new Timestamp(date.getTime());
    DbSingleton.getInstance().getDsl()
        .insertInto(MEETINGUSER,
            MEETINGUSER.MEETINGID, MEETINGUSER.USERLOGIN, MEETINGUSER.JOINTIME)
        .values(meetingId, login, ts)
        .execute();
    
    new File(System.getProperty("user.dir")+"/upload/"+String.valueOf(meetingId)).mkdir();
    
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.put("meetingid", meetingId);
    result.put("title", title);
    result.put("topic", topic);
    
    ObjectNode on = Accounts.web_getData(login,sid);
    result.put("hostname", on.get("name").textValue());
    
    result.put("starttime", ts.toString());
    result.putNull("endtime");
    result.put("members", 1);
    result.put("permissions", "host");
    result.put("accessCode", hash);
    return result;
  }
  
  public static Result stop(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");
    
    String login = json.findPath("login").textValue();
    String sid = json.findPath("sid").textValue();
    String meetingId = json.findPath("meetingid").textValue();
    
    return ok(web_stop(login, sid, meetingId));
  }
  
  public static ObjectNode web_stop(String login, String sid, String meetingId){
    if(login==null || meetingId==null || sid==null)
      return errorObject("incorrect data");
    
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    
    if(!userIsA_Host(login, meetingId))
      return errorObject("access denied");
    
    if(meetingIsAlreadyFinish(meetingId))
      return errorObject("already finished");
    
    java.util.Date date= new java.util.Date();
    
    DbSingleton.getInstance().getDsl()
    .update(MEETING)
    .set(MEETING.ENDTIME, new Timestamp(date.getTime()))
    .where(MEETING.ID.equal(Integer.parseInt(meetingId))).execute();
    
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    return result;
  }
  
  public static Result edit(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");
    
    String login = json.findPath("login").textValue();
    String sid = json.findPath("sid").textValue();
    String meetingId = json.findPath("meetingid").textValue();
    String abilityToSendFiles = json.findPath("abilityToSendFiles").textValue();
    String title = json.findPath("title").textValue();
    String topic = json.findPath("topic").textValue();
    
    return ok(web_edit(login, sid, meetingId, abilityToSendFiles, title, topic));
  }
  
  public static ObjectNode web_edit(String login, String sid, String meetingId, String abilityToSendFiles, String title, String topic){
    if(login==null || sid==null || meetingId==null)
      return errorObject("incorrect data");
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    
    if(!userIsA_Host(login, meetingId))
      return errorObject("access denied");
    
    if(abilityToSendFiles!=null){
      boolean permit;
      if(!abilityToSendFiles.equals("true") && !abilityToSendFiles.equals("false"))
        return errorObject("incorrect data");
      else if (abilityToSendFiles.equals("true"))
        permit = true;
      else
        permit = false;
      DbSingleton.getInstance().getDsl().update(MEETING)
      .set(MEETING.ABILITYTOSENDFILES,permit)
      .where(MEETING.ID.equal(Integer.parseInt(meetingId))).execute();
    }
    
    if(title!=null){
      DbSingleton.getInstance().getDsl().update(MEETING)
      .set(MEETING.TITLE, title)
      .where(MEETING.ID.equal(Integer.parseInt(meetingId))).execute();
    }
    
    if(topic!=null){
      DbSingleton.getInstance().getDsl().update(MEETING)
      .set(MEETING.TOPIC, topic)
      .where(MEETING.ID.equal(Integer.parseInt(meetingId))).execute();
    }
    
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    return result;
  }
  
  public static Result adduser(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");

    String login = json.findPath("login").textValue();
    String sid = json.findPath("sid").textValue();
    String meetingId = json.findPath("meetingid").textValue();
    String accessCode = json.findPath("accessCode").textValue();
    
    return ok(web_addUser(login, sid, meetingId, accessCode));
  }
  
  public static ObjectNode web_addUser(String login, String sid, String meetingId, String accessCode){
    if(login==null || sid==null || meetingId==null || accessCode==null)
      return errorObject("incorrect data");
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    if(codeIsWrong(login, meetingId, accessCode))
      return errorObject("incorrect accessCode");
    if(userIsA_MemberOfMeeting(login, meetingId))
      return errorObject("you are a member");
    if(meetingIsAlreadyFinish(meetingId))
      return errorObject("meeting finished");
    
    java.util.Date date= new java.util.Date();
    Record record = DbSingleton.getInstance().getDsl()
        .insertInto(MEETINGUSER,
            MEETINGUSER.MEETINGID, MEETINGUSER.USERLOGIN, MEETINGUSER.JOINTIME)
        .values(Integer.parseInt(meetingId), login, new Timestamp(date.getTime()))
        .returning(MEETINGUSER.ID)
        .fetchOne();
    
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    
    ObjectNode on = Meetings.web_getList(login,sid);
    
    ArrayNode array = (ArrayNode) on.get("meetings");
    Iterator<JsonNode> it = array.elements();
    while(it.hasNext()){
      JsonNode jn = it.next();
      if (jn.get("meetingid") == null )
        continue;
      if (Integer.parseInt(meetingId) == jn.get("meetingid").asInt()){
        result.put("meetingid", jn.get("meetingid").asInt()).asInt();
        result.put("title", jn.get("title"));
        result.put("topic", jn.get("topic"));
        result.put("hostname", jn.get("hostname"));
        result.put("starttime", jn.get("starttime"));
        result.put("endtime", jn.get("endtime"));
        result.put("members", jn.get("members"));
        result.put("permissions", jn.get("permissions"));
        result.put("accessCode", jn.get("accessCode"));
        break;
      }
    }
    return result;
  }

  public static Result getList(String login, String sid){
    return ok(web_getList(login, sid));
  }
  
  public static ObjectNode web_getList(String login, String sid){
    if(login==null || sid==null)
      return errorObject("incorrect data");
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    
    ObjectNode result = Json.newObject();
    ArrayNode array = Json.newObject().arrayNode();
    
    org.jooq.Result<Record8<Integer, String, String, Timestamp, Timestamp, Boolean, String, String>> record = 
        DbSingleton.getInstance().getDsl()
        .select(MEETING.ID, MEETING.TITLE, MEETING.TOPIC, MEETING.STARTTIME, 
            MEETING.ENDTIME, MEETING.ABILITYTOSENDFILES, MEETING.AUTHORLOGIN, MEETING.ACCESSCODE)
        .from(MEETING)
        .join(MEETINGUSER)
        .on(MEETING.ID.equal(MEETINGUSER.MEETINGID))
        .where(MEETINGUSER.USERLOGIN.equal(login))
        .orderBy(MEETING.STARTTIME.desc()).fetch();
    
    int count = record.size();
    
    for(int i=0; i<count; i++){
      ObjectNode meeting = Json.newObject();
      
      meeting.put("meetingid", record.getValue(i, MEETING.ID));
      meeting.put("title", record.getValue(i, MEETING.TITLE));
      meeting.put("topic", record.getValue(i, MEETING.TOPIC));
      
      org.jooq.Result<Record1<String>> recordHost = 
          DbSingleton.getInstance().getDsl()
          .select(USER.NAME)
          .from(USER)
          .where(USER.LOGIN.equal(record.getValue(i, MEETING.AUTHORLOGIN))).fetch();
      
      meeting.put("hostname", recordHost.getValue(0, USER.NAME));
      meeting.put("starttime", record.getValue(i, MEETING.STARTTIME).toString());
      
      Timestamp ts = record.getValue(i, MEETING.ENDTIME);
      if(ts==null)
        meeting.putNull("endtime");
      else
        meeting.put("endtime", record.getValue(i, MEETING.ENDTIME).toString());
      
      org.jooq.Result<Record> recordMembers = 
          DbSingleton.getInstance().getDsl()
          .select()
          .from(MEETINGUSER)
          .where(MEETINGUSER.MEETINGID.equal(record.getValue(i, MEETING.ID))).fetch();
      
      meeting.put("members", recordMembers.size());
      boolean upl = record.getValue(i, MEETING.ABILITYTOSENDFILES);
      if(login.equals(record.getValue(i, MEETING.AUTHORLOGIN)))
        meeting.put("permissions", "host");
      else if(upl)
        meeting.put("permissions", "memberUpload");
      else
        meeting.put("permissions", "member");
      meeting.put("accessCode", record.getValue(i, MEETING.ACCESSCODE));
      array.add(meeting);
    }
    result.put("status", "ok");
    result.put("meetings", array);
    return result;
  }
  
  
  public static Result getDetails(String meetingid, String login, String sid){
    return ok(web_getDetails(meetingid,login, sid));
  }
  
  public static ObjectNode web_getDetails(String meetingid, String login, String sid){
    if(login==null || sid==null)
      return errorObject("incorrect data");
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    ObjectNode result = Json.newObject();
    
    org.jooq.Result<Record8<Integer, String, String, Timestamp, Timestamp, Boolean, String, String>> record = 
        DbSingleton.getInstance().getDsl()
        .select(MEETING.ID, MEETING.TITLE, MEETING.TOPIC, MEETING.STARTTIME, 
            MEETING.ENDTIME, MEETING.ABILITYTOSENDFILES, MEETING.AUTHORLOGIN, MEETING.ACCESSCODE)
        .from(MEETING)
        .join(MEETINGUSER)
        .on(MEETING.ID.equal(MEETINGUSER.MEETINGID))
        .where(MEETINGUSER.USERLOGIN.equal(login))
        .and(MEETING.ID.equal(Integer.parseInt(meetingid)))
        .fetch();
    
    if(record.size()==0)
      return errorObject("access denied");
    
    result.put("status", "ok");
    result.put("meetingid", record.getValue(0, MEETING.ID)).asInt();
    result.put("title", record.getValue(0, MEETING.TITLE));
    result.put("topic", record.getValue(0, MEETING.TOPIC));
    
    org.jooq.Result<Record1<String>> recordHost = 
        DbSingleton.getInstance().getDsl()
        .select(USER.NAME)
        .from(USER)
        .where(USER.LOGIN.equal(record.getValue(0, MEETING.AUTHORLOGIN))).fetch();
    
    result.put("hostname", recordHost.getValue(0, USER.NAME));
    result.put("starttime", record.getValue(0, MEETING.STARTTIME).toString());
    
    Timestamp ts = record.getValue(0, MEETING.ENDTIME);
    if(ts==null)
      result.putNull("endtime");
    else
      result.put("endtime", record.getValue(0, MEETING.ENDTIME).toString());
    
    org.jooq.Result<Record> recordMembers = 
        DbSingleton.getInstance().getDsl()
        .select()
        .from(MEETINGUSER)
        .where(MEETINGUSER.MEETINGID.equal(record.getValue(0, MEETING.ID))).fetch();
    
    result.put("members", recordMembers.size());
    boolean upl = record.getValue(0, MEETING.ABILITYTOSENDFILES);
    if(login.equals(record.getValue(0, MEETING.AUTHORLOGIN)))
      result.put("permissions", "host");
    else if(upl)
      result.put("permissions", "memberUpload");
    else
      result.put("permissions", "member");
    result.put("accessCode", record.getValue(0, MEETING.ACCESSCODE));
    return result;
  }
  
  public static boolean userIsA_MemberOfMeeting(String login,
      String meetingId) {
    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl()
        .select()
        .from(MEETINGUSER)
        .where(MEETINGUSER.MEETINGID.equal(Integer.parseInt(meetingId)))
        .and(MEETINGUSER.USERLOGIN.equal(login)).fetch();
        if(record.isNotEmpty())
          return true;  
        else
          return false;
  }

  private static boolean checkIsSidCorrect(String login, String sid) {
//    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl().select().from(USER).where(USER.ID.equal(new Integer(login)))
//        .and(USER.SESSIONHASH.equal(sid)).fetch();
    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl().select().from(SESSION)
        .where(SESSION.USERLOGIN.equal(login)).and(SESSION.SID.equal(sid)).fetch();
        if(record.isNotEmpty())
          return true;  
        else
          return false;
  }
  
  private static boolean userIsA_Host(String login, String meetingId) {
    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl()
          .select()
          .from(MEETING)
          .where(MEETING.ID.equal(Integer.parseInt(meetingId)))
          .and(MEETING.AUTHORLOGIN.equal(login))
            .fetch();
        if(record.isNotEmpty())
          return true;  
        else
          return false;
  }
  
  private static boolean meetingIsAlreadyFinish(String meetingId) {
    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl()
          .select()
          .from(MEETING)
          .where(MEETING.ID.equal(Integer.parseInt(meetingId)))
          .and(MEETING.ENDTIME.isNotNull())
            .fetch();
        if(record.isNotEmpty())
          return true;  
        else
          return false;
  }
  
  private static boolean codeIsWrong(String login, String meetingId,
      String accessCode) {
    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl()
        .select()
        .from(MEETING)
        .where(MEETING.ID.equal(Integer.parseInt(meetingId)))
        .and(MEETING.ACCESSCODE.equal(accessCode))
          .fetch();
    if(record.isEmpty())
      return true;  
    else
      return false;
  }
  

  private static Result errorResult(String msg) {
    return ok(errorObject(msg));
  }
  
  private static ObjectNode errorObject(String msg){
    ObjectNode result = Json.newObject();
    result.put("status", "failed");
    result.put("reason", msg);
    return result;
  }
}




Java Source Code List

Dialogs.ServerOptionsLoggedIn.java
Dialogs.ServerOptionsLoggedOut.java
asynctasks.HttpGetListMeetings.java
asynctasks.HttpGetPersonalData.java
asynctasks.HttpGetServerName.java
asynctasks.HttpPostNewMeeting.java
asynctasks.HttpPostRequestLogInAlreadyExistsUser.java
asynctasks.HttpPostRequestLogInFirstTime.java
asynctasks.HttpPostRequestLogIn.java
asynctasks.HttpPostSignUp.java
asynctasks.HttpPutSendFile.java
asynctasks.RefreshMeetingProgress.java
com.TrololoCompany.meetingdataexchangeAdapters.FileAdapter.java
com.TrololoCompany.meetingdataexchangeAdapters.MeetingAdapter.java
com.TrololoCompany.meetingdataexchangeAdapters.ServerAdapter.java
com.TrololoCompany.meetingdataexchange.AddNewMeetingActivity.java
com.TrololoCompany.meetingdataexchange.AddServerActivityFail.java
com.TrololoCompany.meetingdataexchange.AddServerActivitySuccess.java
com.TrololoCompany.meetingdataexchange.AddServerActivity.java
com.TrololoCompany.meetingdataexchange.DisplayQR.java
com.TrololoCompany.meetingdataexchange.LogInActivity.java
com.TrololoCompany.meetingdataexchange.MainActivity.java
com.TrololoCompany.meetingdataexchange.MeetingDetails.java
com.TrololoCompany.meetingdataexchange.ServerList.java
com.TrololoCompany.meetingdataexchange.ServerManageActivity.java
com.TrololoCompany.meetingdataexchangeServices.MeetingDetailsRefresh.java
com.TrololoCompany.meetingdataexchangeServices.MeetingServerCommunication.java
com.TrololoCompany.meetingdataexchangeServices.ServiceHandlers.java
com.TrololoCompany.meetingdataexchange.SignUpActivity.java
com.TrololoCompany.meetingdataexchange.util.SystemUiHiderBase.java
com.TrololoCompany.meetingdataexchange.util.SystemUiHiderHoneycomb.java
com.TrololoCompany.meetingdataexchange.util.SystemUiHider.java
com.TrololoCompany.meetingdataexchangedataBase.CommentEntity.java
com.TrololoCompany.meetingdataexchangedataBase.DataBaseHelper.java
com.TrololoCompany.meetingdataexchangedataBase.FileEntity.java
com.TrololoCompany.meetingdataexchangedataBase.MeetingEntity.java
com.TrololoCompany.meetingdataexchangedataBase.ServerEntity.java
controllers.Accounts.java
controllers.FilesManagement.java
controllers.GeneralStuff.java
controllers.Mailing.java
controllers.Meetings.java
dataBase.CommentEntity.java
dataBase.DataBaseHelper.java
dataBase.FileEntity.java
dataBase.MeetingEntity.java
dataBase.MettingEntity.java
dataBase.ServerEntity.java
dataBase.Server.java
fileMaintenance.FileMaintenance.java
lists.MeetingList.java
lists.ServerList.java
meeting_options.FireMissilesDialogFragment.java
meeting_options.MeetDetOnPageListener.java
meeting_options.MeetDetTabListener.java
meeting_options.MeetingAddItems.java
meeting_options.MeetingDescription.java
meeting_options.MeetingProgressUIRefresh.java
meeting_options.MeetingProgress.java
meeting_options.MeetingTabPagerAdapter.java
meeting_options.MyOnPageChangeListener.java
meeting_options.MyTabListener.java
meeting_options.RefreshMeetingProgressListView.java
meeting_options.TabsPagerAdapter.java
models.DbSingleton.java
models.DefaultSchema.java
models.Keys.java
models.Tables.java
models.tables.Comment.java
models.tables.File.java
models.tables.Meeting.java
models.tables.Meetinguser.java
models.tables.Session.java
models.tables.SqliteSequence.java
models.tables.User.java
models.tables.records.CommentRecord.java
models.tables.records.FileRecord.java
models.tables.records.MeetingRecord.java
models.tables.records.MeetinguserRecord.java
models.tables.records.SessionRecord.java
models.tables.records.SqliteSequenceRecord.java
models.tables.records.UserRecord.java
serverCommunicator.CheckIsServerExists.java
serverCommunicator.CommentsHelper.java
serverCommunicator.CommunicationHelper.java
serverCommunicator.Communication.java
serverCommunicator.FileHelper.java
serverCommunicator.FileListRefreshService.java
serverCommunicator.GetMeetingListHelper.java
serverCommunicator.GetPersonalDataHelper.java
serverCommunicator.HttpGetRequest.java
serverCommunicator.HttpPostRequest.java
serverCommunicator.LogInHelper.java
serverCommunicator.MeetingHelper.java
serverCommunicator.NewMeetingHelper.java
serverCommunicator.RegistrationHelper.java
tools.MD5Checksum.java