private void handleJsonCreateQuotation(RequestAndResponse requestAndResponse) throws IOException, ServletException {
  requestAndResponse.setResponseContentTypeJson();
  String url;
  String title;
  String quotation;
  String note;
  String sessionId;
  try {
    final JsonNodeHelper json=getJsonNode(requestAndResponse);
    url=json.getString(DbLogic.Constants.url);
    title=json.getString(DbLogic.Constants.title);
    quotation=json.getString(DbLogic.Constants.quotation);
    note=json.getString(DbLogic.Constants.note);
    sessionId=json.getString("sessionId");
  }
 catch (  final IOException e) {
    returnJson400(requestAndResponse,servletText.errorJson());
    return;
  }
  if (!EntryAttributeValidator.isNoteValid(note)) {
    returnJson400(requestAndResponse,servletText.errorNoteIsInvalid());
    return;
  }
  if (!EntryAttributeValidator.isQuotationValid(quotation)) {
    returnJson400(requestAndResponse,servletText.errorQuotationIsInvalid());
    return;
  }
  if (!EntryAttributeValidator.isUrlValid(url)) {
    returnJson400(requestAndResponse,servletText.errorUrlIsInvalid());
    return;
  }
  if (!EntryAttributeValidator.isSourceTitleValid(title)) {
    returnJson400(requestAndResponse,servletText.errorTitleIsInvalid());
    return;
  }
  final Errors errors=new Errors();
  try {
    final Long time=new Long(System.currentTimeMillis());
    String userId=null;
    if (sessionManager != null) {
      final HttpSession session=sessionManager.getSession(sessionId);
      if (session != null && session.getAttribute(sessionUserIdAttribute) != null) {
        userId=(String)session.getAttribute(sessionUserIdAttribute);
      }
    }
    final User user=dbLogic.getUserById(userId);
    if (user == null) {
      returnJson400(requestAndResponse,servletText.errorNoAccountFound());
      return;
    }
    if (user.getIsAccountClosed()) {
      returnJson400(requestAndResponse,servletText.errorAccountIsClosed());
      return;
    }
    final Entry source=dbLogic.updateOrCreateSource(user,null,url,title,time,time,isUserAnAdmin(requestAndResponse),errors);
    if (source == null) {
      returnJson400(requestAndResponse,errors);
      return;
    }
    final Entry entry=dbLogic.createEntryQuotation(user,source,quotation,note,time,isUserAnAdmin(requestAndResponse),errors);
    if (entry == null) {
      returnJson400(requestAndResponse,errors);
      return;
    }
    requestAndResponse.print("{\"success\":true, " + "\"quotationId\":\"" + entry.getId() + "\","+ "\"sourceId\":\""+ source.getId()+ "\"}");
    dbLogic.commit();
  }
 catch (  final PersistenceException e) {
    logger.log(Level.INFO,"Exception",e);
    returnJson500(requestAndResponse,servletText.errorInternalDatabase());
  }
}

private void handleJsonCreateQuotation ( RequestAndResponse requestAndResponse ) throws IOException , ServletException { requestAndResponse . setResponseContentTypeJson ( ) ; String url ; String title ; String quotation ; String note ; String sessionId ; try { final JsonNodeHelper json = getJsonNode ( requestAndResponse ) ; url = json . getString ( DbLogic . Constants . url ) ; title = json . getString ( DbLogic . Constants . title ) ; quotation = json . getString ( DbLogic . Constants . quotation ) ; note = json . getString ( DbLogic . Constants . note ) ; sessionId = json . getString ( "sessionId" ) ; } catch ( final IOException e ) { returnJson400 ( requestAndResponse , servletText . errorJson ( ) ) ; return ; } if ( ! EntryAttributeValidator . isNoteValid ( note ) ) { returnJson400 ( requestAndResponse , servletText . errorNoteIsInvalid ( ) ) ; return ; } if ( ! EntryAttributeValidator . isQuotationValid ( quotation ) ) { returnJson400 ( requestAndResponse , servletText . errorQuotationIsInvalid ( ) ) ; return ; } if ( ! EntryAttributeValidator . isUrlValid ( url ) ) { returnJson400 ( requestAndResponse , servletText . errorUrlIsInvalid ( ) ) ; return ; } if ( ! EntryAttributeValidator . isSourceTitleValid ( title ) ) { returnJson400 ( requestAndResponse , servletText . errorTitleIsInvalid ( ) ) ; return ; } final Errors errors = new Errors ( ) ; try { final Long time = new Long ( System . currentTimeMillis ( ) ) ; String userId = null ; if ( sessionManager != null ) { final HttpSession session = sessionManager . getSession ( sessionId ) ; if ( session != null && session . getAttribute ( sessionUserIdAttribute ) != null ) { userId = ( String ) session . getAttribute ( sessionUserIdAttribute ) ; } } final User user = dbLogic . getUserById ( userId ) ; if ( user == null ) { returnJson400 ( requestAndResponse , servletText . errorNoAccountFound ( ) ) ; return ; } if ( user . getIsAccountClosed ( ) ) { returnJson400 ( requestAndResponse , servletText . errorAccountIsClosed ( ) ) ; return ; } final Entry source = dbLogic . updateOrCreateSource ( user , null , url , title , time , time , isUserAnAdmin ( requestAndResponse ) , errors ) ; if ( source == null ) { returnJson400 ( requestAndResponse , errors ) ; return ; } final Entry entry = dbLogic . createEntryQuotation ( user , source , quotation , note , time , isUserAnAdmin ( requestAndResponse ) , errors ) ; if ( entry == null ) { returnJson400 ( requestAndResponse , errors ) ; return ; } requestAndResponse . print ( "{\"success\":true, " + "\"quotationId\":\"" + entry . getId ( ) + "\"," + "\"sourceId\":\"" + source . getId ( ) + "\"}" ) ; dbLogic . commit ( ) ; } catch ( final PersistenceException e ) { logger . log ( Level . INFO , "Exception" , e ) ; returnJson500 ( requestAndResponse , servletText . errorInternalDatabase ( ) ) ; } }
part of the json api . creates a new quotation .
