Example usage for org.springframework.http HttpStatus FORBIDDEN

List of usage examples for org.springframework.http HttpStatus FORBIDDEN

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus FORBIDDEN.

Prototype

HttpStatus FORBIDDEN

To view the source code for org.springframework.http HttpStatus FORBIDDEN.

Click Source Link

Document

403 Forbidden .

Usage

From source file:com.siblinks.ws.service.impl.UploadEssayServiceImpl.java

/**
 * {@inheritDoc}/*from w  w  w.j  a  v a2s  .c  om*/
 */
@Override
@RequestMapping(value = "/rateEssay", method = RequestMethod.POST)
public ResponseEntity<Response> rateEssay(@RequestBody final EssayUploadData essayUploadData) {
    String entityName = null;
    boolean status = false;
    SimpleResponse response = null;
    TransactionStatus statusDao = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        String uploadEssayId = essayUploadData.getUploadEssayId();
        String uid = essayUploadData.getUid();
        String rate = essayUploadData.getRating();

        // Return if vid or uid
        if (StringUtil.isNull(uploadEssayId) || StringUtil.isNull(uid) || StringUtil.isNull(rate)) {
            response = new SimpleResponse(SibConstants.FAILURE, "essay", "rateEssay",
                    "Parameter cannot null or Emppty.");
            return new ResponseEntity<Response>(response, HttpStatus.OK);
        }
        TransactionDefinition def = new DefaultTransactionDefinition();
        statusDao = transactionManager.getTransaction(def);
        // Check user rated yet
        Object[] queryParams = new Object[] { uid, uploadEssayId };
        List<Object> videoRated = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_GET_USER_RATE_ESSAY,
                queryParams);

        boolean isRated = videoRated.size() > 0 ? true : false;

        if (!isRated) {
            // New rating
            entityName = SibConstants.SqlMapper.SQL_SIB_RATE_ESSAY;
            queryParams = new Object[] { uploadEssayId, uid, rate };
            status = dao.insertUpdateObject(entityName, queryParams);

            Object[] queryUpdateRate = { rate, uploadEssayId };
            dao.insertUpdateObject(SibConstants.SqlMapper.SQL_UPDATE_AVG_RATE_ESSAY, queryUpdateRate);
            // Activity Log
            activiLogService.insertActivityLog(new ActivityLogData(SibConstants.TYPE_ESSAY, "C",
                    "You rated a artical", uid, String.valueOf(uploadEssayId)));
        } else {
            Map<String, Integer> object = (Map<String, Integer>) videoRated.get(0);
            int rateOld = object.get(Parameters.RATING);
            int rateNew = Integer.parseInt(rate);
            if (rateOld != rateNew) {
                // Update rating
                queryParams = new Object[] { rate, uploadEssayId, uid };
                entityName = SibConstants.SqlMapper.SQL_SIB_RATE_UPDATE_ESSAY;
                status = dao.insertUpdateObject(entityName, queryParams);

                Object[] queryUpdateRate = { rateNew - rateOld, uploadEssayId };
                status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_UPDATE_AVG_RATE_ESSAY_AGAIN,
                        queryUpdateRate);
                // Activity Log
                activiLogService.insertActivityLog(new ActivityLogData(SibConstants.TYPE_ESSAY, "U",
                        "You updated the rating a artical", uid, String.valueOf(uploadEssayId)));
            }
        }

        transactionManager.commit(statusDao);
        logger.info("Rate essay successful " + new Date());

        response = new SimpleResponse("" + status, "essay", "rateEssay", uploadEssayId);
    } catch (Exception e) {
        if (statusDao != null) {
            transactionManager.rollback(statusDao);
        }
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, "essay", "rateEssay", e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UploadEssayServiceImpl.java

/**
 * {@inheritDoc}/*w ww .  j  a  v  a  2s.co m*/
 */
@Override
@RequestMapping(value = "/getUserRateEssay/{uid}/{uploadEssayId}", method = RequestMethod.GET)
public ResponseEntity<Response> getUserRateEssay(@PathVariable(value = "uid") final String uid,
        @PathVariable(value = "uploadEssayId") final String uploadEssayId) {
    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        // Return if vid or uid
        if (StringUtil.isNull(uploadEssayId) || StringUtil.isNull(uid)) {
            response = new SimpleResponse(SibConstants.FAILURE, "artical", "checkRateEssay",
                    "Parameter cannot null or Emppty.");
        } else {

            List<Object> readObjects = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_GET_USER_RATE_ESSAY,
                    new Object[] { uid, uploadEssayId });
            response = new SimpleResponse(SibConstants.SUCCESS, "essay", "getUserRateEssay", readObjects);
        }
    } catch (Exception e) {
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, "essay", "getUserRateEssay", e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}//from w ww  . ja va  2s  . c om
 */
@Override
@RequestMapping(value = "/getUsers", method = RequestMethod.POST)
public ResponseEntity<Response> getUsers(@RequestBody final RequestData request) {
    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        Object[] queryParams = { request.getRequest_data().getUsertype() };

        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_USERID, queryParams);

        response = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}/*from ww w.  ja  va  2s.c om*/
 */
@Override
@RequestMapping(value = "/getAllUsers", method = RequestMethod.GET)
public ResponseEntity<Response> getAllUsers(@RequestParam(value = "_search") final String search,
        @RequestParam(value = "nd") final String nd, @RequestParam(value = "rows") final int rows,
        @RequestParam(value = "page") final int page, @RequestParam(value = "sidx") final String sidx,
        @RequestParam(value = "sord") final String sord) {

    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        // String whereClase = " WHERE userType=? ";
        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_ALL_USERS, new Object[] {});

        // Return for rows
        response = new SimpleResponse(readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, "users", "getAllUsers", e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}// w ww . ja va2s  .c  o m
 */
@Override
@RequestMapping(value = "/getUserNotes", method = RequestMethod.POST)
public ResponseEntity<Response> getUserNotes(@RequestBody final RequestData request) {

    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }
        Object[] queryParams = { request.getRequest_data().getUid() };
        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_NOTE_USER, queryParams);

        response = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, "users", "getUserNotes", e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}/*from  w  w w  .ja  v a2  s .  c o  m*/
 */
@Override
@RequestMapping(value = "/getStudentMentors", method = RequestMethod.POST)
public ResponseEntity<Response> getStudentMentors(@RequestBody final RequestData request) {

    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }
        Object[] queryParams = { request.getRequest_data().getUid() };

        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_STUDENT_MENTORS, queryParams);

        response = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, "users", "getStudentMentors", e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}// w  ww  .  j av a 2s. c  om
 */
@Override
@RequestMapping(value = "/collegesOrUniversities", method = RequestMethod.POST)
public ResponseEntity<Response> collegesOrUniversities(@RequestBody final RequestData request) {

    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        Object[] queryParams = {};
        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_COL_UNIVERSITIES, queryParams);

        response = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}/*from  w  w  w  . java  2 s.  c  o m*/
 */
@Override
@RequestMapping(value = "/majors", method = RequestMethod.POST)
public ResponseEntity<Response> majors(@RequestBody final RequestData request) {

    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }
        Object[] queryParams = {};

        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_MAJORS, queryParams);

        response = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}/* ww  w. ja  v a2  s . co  m*/
 */
@Override
@RequestMapping(value = "/extracurricularActivities", method = RequestMethod.POST)
public ResponseEntity<Response> extracurricularActivities(@RequestBody final RequestData request) {

    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }
        Object[] queryParams = {};
        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_EXTRA_ACTIVITIES, queryParams);
        response = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.UserServiceImpl.java

/**
 * {@inheritDoc}/*from  w  w  w  .j  av  a2s  .com*/
 */
@SuppressWarnings("rawtypes")
@Override
@RequestMapping(value = "/signupcomplete", method = RequestMethod.POST)
public ResponseEntity<Response> signupcomplete(@RequestBody final RequestData request)
        throws FileNotFoundException {

    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        Object[] queryParams = { request.getRequest_data().getEmail(), request.getRequest_data().getPassword(),
                request.getRequest_data().getFirstname(), request.getRequest_data().getLastname(),
                request.getRequest_data().getUsertype(), request.getRequest_data().getDob(),
                request.getRequest_data().getEducation(), request.getRequest_data().getAccomp(),
                request.getRequest_data().getColmajor(), request.getRequest_data().getActivities(),
                request.getRequest_data().getHelpin(), request.getRequest_data().getFamilyincome(),
                request.getRequest_data().getYourdream(), environment.getProperty("directoryImageAvatar") };

        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_REGISTER_USER_EXIST,
                queryParams);

        boolean status = Boolean.FALSE;
        if (readObject.size() == 0) {

            List<Object> msgs1 = null;
            status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIGNUP_COMPLETE_USER, queryParams);

            if (status) {
                msgs1 = dao.readObjects(SibConstants.SqlMapper.SQL_GET_USERID, queryParams);
                if (msgs1 != null && msgs1.size() > 0) {
                    ((Map) msgs1.get(0)).get(Parameters.USERID).toString();
                }
            }

            if (request.getRequest_data().getColmajor() != null) {
                new ArrayList<String>(Arrays.asList(request.getRequest_data().getColmajor().split(",")));
            }

            if (request.getRequest_data().getActivities() != null) {
                new ArrayList<String>(Arrays.asList(request.getRequest_data().getActivities().split(",")));
            }

            if (request.getRequest_data().getHelpin() != null) {
                new ArrayList<String>(Arrays.asList(request.getRequest_data().getHelpin().split(",")));
            }
        } else {
            readObject = new ArrayList<Object>();
            readObject.add("Email Address is Already Registered");
        }

        response = new SimpleResponse("" + status, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}