Example usage for java.util HashSet toString

List of usage examples for java.util HashSet toString

Introduction

In this page you can find the example usage for java.util HashSet toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:cz.cas.lib.proarc.webapp.server.rest.DigitalObjectResource.java

private List<Item> addMembers(DigitalObjectHandler parent, List<String> toAddPids,
        Map<String, Item> memberSearchMap) throws DigitalObjectException {

    String parentPid = parent.getFedoraObject().getPid();
    HashSet<String> toAddPidSet = new HashSet<String>(toAddPids);
    ArrayList<Item> added = new ArrayList<Item>(toAddPidSet.size());
    if (toAddPidSet.isEmpty()) {
        return added;
    }//from   w ww  . java 2  s  . c  o m
    RelationEditor editor = parent.relations();
    List<String> members = editor.getMembers();
    // add new members
    for (String addPid : toAddPids) {
        if (!members.contains(addPid)) {
            members.add(addPid);
            Item item = memberSearchMap.get(addPid);
            if (item == null) {
                throw RestException.plainNotFound("pid", toAddPidSet.toString());
            }
            item.setParentPid(parentPid);
            added.add(item);
        } else {
            throw RestException.plainText(Status.BAD_REQUEST, parentPid + " already contains: " + addPid);
        }
    }
    // write if any change
    if (!added.isEmpty()) {
        editor.setMembers(members);
        editor.write(editor.getLastModified(), session.asFedoraLog());
    }
    return added;
}

From source file:web.CarryonupdateController.java

/**
 * This method is called by the spring framework. The configuration
 * for this controller to be invoked is based on the pagetype and
 * is set in the urlMapping property in the spring config file.
 *
 * @param request the <code>HttpServletRequest</code>
 * @param response the <code>HttpServletResponse</code>
 * @throws ServletException/*from   w w w .j a  va  2 s. c o m*/
 * @throws IOException
 * @return ModelAndView this instance is returned to spring
 */
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        ModelAndView m = super.handleRequest(request, response);
    } catch (Exception e) {
        return handleError("error in handleRequest", e);
    }

    outOfSession(request, response);

    if (RegexStrUtil.isNull(login) && RegexStrUtil.isNull(member)) {
        return handleUserpageError("Login & member are null.");
    }

    String category = request.getParameter(DbConstants.CATEGORY);
    boolean isCobrand = false;
    if (!RegexStrUtil.isNull(request.getParameter(DbConstants.IS_COBRAND))) {
        isCobrand = request.getParameter(DbConstants.IS_COBRAND).equals((Object) "1");
    }

    if ((!RegexStrUtil.isNull(category) && category.equals(DbConstants.FILE_CATEGORY)) || isCobrand) {
        if (!GlobalConst.hddomain.contains(DbConstants.INDIA_CENTURY)) {
            if (!WebUtil.isLicenseProfessional(login)) {
                return handleError(
                        "Cannot access user carryon features or cobrand user in deluxe version." + login);
            }
        }
    }
    if (RegexStrUtil.isNull(category)) {
        return handleError("category is null in CarryonupdateController. " + login);
    }

    // ***************************************************************************
    // This is the only line of code you need to get all session info initialized!
    // Always be the first line before anything else is done. Add to each controller's
    // handlRequest method. Also remember to extend SessionObject.
    // ***************************************************************************

    /**
     *  map blob dao
     */
    if (getDaoMapper() == null) {
        return handleError("DaoMapper is null in carryon update.");
    }
    CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON);
    if (carryonDao == null) {
        return handleError("CarryonDao is null for carryon update.");
    }

    byte[] blob = null;
    String mtype = null;
    if (!RegexStrUtil.isNull(category)) {
        int catVal = new Integer(category).intValue();
        if (catVal < GlobalConst.categoryMinSize || catVal > GlobalConst.categoryMaxSize) {
            return handleError("category values are not correct" + catVal);
        }
    }

    List fileList = null;
    DiskFileUpload upload = null;
    try {
        boolean isMultipart = FileUpload.isMultipartContent(request);
        // Create a new file upload handler
        upload = new DiskFileUpload();
        /** originally set to 10MB **/
        if (!DiaryAdmin.isDiaryAdmin(login)) {
            upload.setSizeMax((long) 10000000);
        } else {
            upload.setSizeMax(GlobalConst.maxUploadSize);
        }

        // Parse the request
        fileList = upload.parseRequest(request);
    } catch (Exception e) {
        return handleError("Exception occurred in uploading the photo file.", e);
    }

    long fieldsize = 0;
    String fieldname, fieldvalue;
    fieldname = fieldvalue = null;

    // educate the fieldnames to this form by using the setFieldName() 
    String label = "btitle";
    String caption = "";
    String tagsLabel = DbConstants.USER_TAGS;
    String fileName = null;
    String usertags = null;
    String btitle = null;

    for (int i = 0; i < fileList.size(); i++) {
        FileItem fileItem = (FileItem) fileList.get(i);
        if (fileItem.isFormField()) {
            fileItem.setFieldName(label);
            fieldname = fileItem.getFieldName();
            if (fieldname.equalsIgnoreCase(DbConstants.USER_TAGS)) {
                usertags = fileItem.getString();
                //logger.info("usertags = " + usertags);
                label = "";
            } else {
                if (fieldname.equalsIgnoreCase("btitle")) {
                    btitle = fileItem.getString();
                    label = DbConstants.CAPTION;
                    //logger.info("btitle = " + btitle);
                    //fileItem.setFieldName(tagsLabel);
                } else {
                    if (fieldname.equalsIgnoreCase("caption")) {
                        caption = fileItem.getString();
                        label = DbConstants.USER_TAGS;
                    } else {
                        fieldvalue = fileItem.getString();
                    }
                }
            }
            /* set the filename */
        } else {
            blob = fileItem.get();
            mtype = fileItem.getContentType();
            long maxSize = upload.getSizeMax();
            /* filename */
            fileName = fileItem.getName();
            fieldsize = fileItem.getSize();
        }
    }

    if (RegexStrUtil.isNull(btitle)) {
        btitle = fileName;
    }

    if ((fieldsize <= 0) || (RegexStrUtil.isNull(mtype)) || (RegexStrUtil.isNull(btitle)) || (blob == null)) {
        return handleError("fieldsize/mtype/btitle/blob one of them is empty, cannot upload files.");
    }

    CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND);
    if (cobrandDao == null) {
        return handleError("cobrandDao is null for CarryonupdateController");
    }

    DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE);
    if (displayDao == null) {
        return handleError("displayDao is null for CarryonupdateController");
    }

    try {
        if (isCobrand) {
            String ftype = request.getParameter(DbConstants.TYPE);
            if (RegexStrUtil.isNull(ftype)) {
                return handleError("ftype is null, CarryonUpdateController() ");
            }
            if (ftype.equals(DbConstants.COBRAND_HEADER) || ftype.equals(DbConstants.COBRAND_FOOTER)) {
                cobrandDao.addUserCobrand(blob, ftype, loginInfo.getValue(DbConstants.LOGIN_ID), login);
            } else {
                return handleError("cobrand type is not a header or footer in CarryonUpdateController ");
            }
        } else {
            if (btitle.length() > GlobalConst.blobTitleSize) {
                btitle = btitle.substring(0, GlobalConst.blobTitleSize);
            }
            int zoom = 100;
            if (!RegexStrUtil.isNull(usertags)) {
                if (usertags.length() > GlobalConst.usertagsSize) {
                    usertags = usertags.substring(0, GlobalConst.usertagsSize);
                }
                usertags = RegexStrUtil.goodText(usertags);
            }

            if (!RegexStrUtil.isNull(caption)) {
                if (caption.length() > GlobalConst.refererSize) {
                    caption = caption.substring(0, GlobalConst.refererSize);
                }
                caption = RegexStrUtil.goodText(caption);
            }

            boolean publishPhoto = displayDao.getDisplayPhotos(login, DbConstants.READ_FROM_SLAVE);
            carryonDao.addCarryon(fieldsize, category, mtype, RegexStrUtil.goodText(btitle), blob, zoom,
                    loginInfo.getValue(DbConstants.LOGIN_ID), login, usertags, caption, publishPhoto);
        }
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in addCarryon/addCobrandUserStreamBlo()", e);
    }

    /**
    * list the files 
    */
    String loginId = loginInfo.getValue(DbConstants.LOGIN_ID);
    List carryon = null;
    List tagList = null;
    HashSet tagSet = null;
    try {
        carryon = carryonDao.getCarryonByCategory(loginId, category, DbConstants.READ_FROM_MASTER);
        tagList = carryonDao.getTags(loginId, DbConstants.READ_FROM_MASTER);
        tagSet = carryonDao.getUniqueTags(tagList);
    } catch (BaseDaoException e) {
        return handleError(
                "Exception occurred in getCarryonByCategory()/getTags carryon update for login " + login, e);
    }

    /**
          * this is resolved to the name of the jsp using ViewResolver
     * if not blob type is images, display files
     */
    if (carryon == null) {
        return handleError("carryon is null.");
    }

    /**
     * display information about the files, if the category of the blobs is files category(1)
     */
    String viewName = DbConstants.EDIT_PHOTOS;
    if (category.equals(DbConstants.FILE_CATEGORY)) {
        viewName = DbConstants.EDIT_FILES;
    }

    Displaypage displaypage = null;
    Userpage cobrand = null;
    try {
        displaypage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_SLAVE);
        cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID));
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in getDisplaypage() for login " + login, e);
    }

    Map myModel = new HashMap();
    myModel.put(viewName, carryon);
    myModel.put(DbConstants.COBRAND, cobrand);
    if (tagSet != null) {
        myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString()));
    }
    myModel.put(DbConstants.LOGIN_INFO, loginInfo);
    myModel.put(DbConstants.DISPLAY_PAGE, displaypage);
    myModel.put(DbConstants.USER_PAGE, userpage);
    myModel.put(DbConstants.SHARE_INFO, shareInfo);
    myModel.put(DbConstants.VISITOR_PAGE, memberUserpage);
    myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
    myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login));
    return new ModelAndView(viewName, "model", myModel);
}

From source file:web.CarryondeleteController.java

/**
 * This method is called by the spring framework. The configuration
 * for this controller to be invoked is based on the pagetype and
 * is set in the urlMapping property in the spring config file.
 *
 * @param request the <code>HttpServletRequest</code>
 * @param response the <code>HttpServletResponse</code>
 * @throws ServletException/*from  ww  w .  j a v  a  2 s.  c o  m*/
 * @throws IOException
 * @return ModelAndView this instance is returned to spring
 */
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        ModelAndView m = super.handleRequest(request, response);
    } catch (Exception e) {
        return handleError("error in handleRequest", e);
    }

    outOfSession(request, response);

    String category = request.getParameter(DbConstants.CATEGORY);
    if (!RegexStrUtil.isNull(category) && category.equals(DbConstants.FILE_CATEGORY)) {
        if (!WebUtil.isLicenseProfessional(login)) {
            return handleError("Cannot access user file features in deluxe version." + login);
        }
    }
    if (RegexStrUtil.isNull(category)) {
        return handleError(
                "categoryid is empty/null while deleting carryon. Forwarding to userpage of login " + login);
    }

    /**
      * error checking
     */
    if (RegexStrUtil.isNull(login) || loginInfo == null) {
        return handleUserpageError("Login || loginInfo is null, CarryondeleteController. ");
    }

    String entryid = request.getParameter(DbConstants.ENTRYID);
    if (RegexStrUtil.isNull(entryid)) {
        return handleError(
                "entryid is empty/null while deleting carryon. Forwarding to userpage of login " + login);
    }
    if (entryid.length() > GlobalConst.entryIdSize) {
        return handleError("entryidSize is > Forwarding to userpage of login " + login);
    }

    int catValue = new Integer(category).intValue();
    if (catValue < GlobalConst.categoryMinSize || catValue > GlobalConst.categoryMaxSize) {
        return handleError("category values is not within the appropriate range, catValue = " + catValue);
    }

    /**
      * delete blob streams from carryon
     */
    if (getDaoMapper() == null) {
        return handleError("DaoMapper is null for delete carryon, login " + login);
    }
    CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON);
    if (carryonDao == null) {
        return handleError("carryonDao is null for delete carryon, login " + login);
    }
    String loginId = loginInfo.getValue(DbConstants.LOGIN_ID);
    try {
        carryonDao.deleteCarryon(entryid, loginId, category, login);
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in deleteCarryon() for login " + login, e);
    }

    List carryon = null;
    List tagList = null;
    HashSet tagSet = null;
    try {
        carryon = carryonDao.getCarryonByCategory(loginId, category, DbConstants.READ_FROM_MASTER);
        tagList = carryonDao.getTags(loginId, DbConstants.READ_FROM_MASTER);
        tagSet = carryonDao.getUniqueTags(tagList);
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in getCarryon() in carryon edit for login " + login, e);
    }

    /**
     * editphotos / editfiles - views
     */
    String viewName = DbConstants.EDIT_PHOTOS;
    if (category != null && category.equalsIgnoreCase(DbConstants.FILE_CATEGORY)) {
        viewName = DbConstants.EDIT_FILES;
    }

    if (carryon == null) {
        return handleError("carryon is null.");
    }

    /*
         * display information about the files.
         */
    DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE);
    if (displayDao == null) {
        return handleError("displayDao is null in carryon edit for login " + login);
    }

    Displaypage displaypage = null;
    try {
        displaypage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_SLAVE);
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in getCarryon() in carryon edit for login " + login, e);
    }

    CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND);
    if (cobrandDao == null) {
        return handleUserpageError("CobrandDao is null, CarryondeleteController");
    }
    Userpage cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID));

    Map myModel = new HashMap();
    myModel.put(viewName, carryon);
    if (tagSet != null) {
        myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString()));
    }
    myModel.put(DbConstants.LOGIN_INFO, loginInfo);
    myModel.put(DbConstants.DISPLAY_PAGE, displaypage);
    myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
    myModel.put(DbConstants.COBRAND, cobrand);
    myModel.put(DbConstants.USER_PAGE, userpage);
    myModel.put(DbConstants.SHARE_INFO, shareInfo);
    myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login));
    return new ModelAndView(viewName, "model", myModel);

    //myModel.put(DbConstants.VISITOR_PAGE, memberUserpage);

}

From source file:com.pinterest.arcee.aws.EC2HostInfoDAOImpl.java

@Override
public Set<String> getTerminatedHosts(Set<String> staleIds) throws Exception {
    HashSet<String> ids = new HashSet<>(staleIds);
    HashSet<String> terminatedHosts = new HashSet<>();
    while (!ids.isEmpty()) {
        DescribeInstancesRequest request = new DescribeInstancesRequest();
        request.setInstanceIds(ids);//from  w  w w  .  j av  a 2  s  . c  om
        try {
            do {
                DescribeInstancesResult results = ec2Client.describeInstances(request);
                List<Reservation> reservations = results.getReservations();
                for (Reservation reservation : reservations) {
                    for (Instance instance : reservation.getInstances()) {
                        int stateCode = instance.getState().getCode();
                        String id = instance.getInstanceId();
                        if (stateCode == TERMINATED_CODE || stateCode == STOPPED_CODE) {
                            LOG.info(String.format("Instance %s has already been terminated or stopped.", id));
                            terminatedHosts.add(id);
                        }

                        ids.remove(id);
                    }
                }
                if (results.getNextToken() == null || results.getNextToken().isEmpty()) {
                    break;
                }
                request = new DescribeInstancesRequest();
                request.setInstanceIds(ids);
                request.setNextToken(results.getNextToken());
            } while (true);
            LOG.debug("Cannot find the following ids in AWS:", ids);
            terminatedHosts.addAll(ids);
            return terminatedHosts;
        } catch (AmazonServiceException ex) {
            Collection<String> invalidHostIds = handleInvalidInstanceId(ex);
            ids.removeAll(invalidHostIds);
            // add invalid host ids to the terminated host list.
            terminatedHosts.addAll(invalidHostIds);
        } catch (AmazonClientException ex) {
            LOG.error(String.format("Get AmazonClientException, exit with terminiatedHost %s",
                    terminatedHosts.toString()), ex);
            return terminatedHosts;
        }
    }
    return terminatedHosts;
}

From source file:web.CaptionupdateController.java

/**
 * This method is called by the spring framework. The configuration
 * for this controller to be invoked is based on the pagetype and
 * is set in the urlMapping property in the spring config file.
 *
 * @param request the <code>HttpServletRequest</code>
 * @param response the <code>HttpServletResponse</code>
 * @throws ServletException/* w  ww  . j  a v a2s  . co  m*/
 * @throws IOException
 * @return ModelAndView this instance is returned to spring
 */
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        ModelAndView m = super.handleRequest(request, response);
    } catch (Exception e) {
        return handleError("error in handleRequest", e);
    }

    outOfSession(request, response);

    String category = request.getParameter(DbConstants.CATEGORY);
    String entryid = request.getParameter(DbConstants.ENTRYID);
    String btitle = request.getParameter(DbConstants.BTITLE);

    if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(btitle) || RegexStrUtil.isNull(category)) {
        return handleError("entryid/btitle/category is null. Forwarding to " + login
                + "in edit photos, CaptionupdateController");
    }

    boolean isFile = false;
    if (category.equals(DbConstants.FILE_CATEGORY)) {
        if (!WebUtil.isLicenseProfessional(login)) {
            return handleError(
                    "Cannot access user file features (caption update for files) in deluxe version." + login);
        }
        isFile = true;
    }

    String caption = request.getParameter(DbConstants.CAPTION);
    String zoom = request.getParameter(DbConstants.ZOOM);
    String usertags = request.getParameter(DbConstants.USER_TAGS);

    if (!RegexStrUtil.isNull(category)) {
        if (!category.equals(DbConstants.FILE_CATEGORY) && !category.equals(DbConstants.PHOTO_CATEGORY)) {
            return handleError("category is neither a file nor a photo, CaptionUpdateController" + category);
        }
    }

    if (entryid.length() > GlobalConst.entryIdSize) {
        return handleError("entryid.length() > WebConstants.entryIdSize, CaptionUpdateController, " + entryid);
    }

    if (btitle.length() > GlobalConst.blobTitleSize) {
        btitle = btitle.substring(0, GlobalConst.blobTitleSize);
    }

    if (!RegexStrUtil.isNull(usertags)) {
        if (usertags.length() > GlobalConst.blobTitleSize) {
            usertags = usertags.substring(0, GlobalConst.blobTitleSize);
        }
        usertags = RegexStrUtil.goodText(usertags);
    }

    boolean def = request.getParameter(DbConstants.DEF) != null
            && request.getParameter(DbConstants.DEF).equalsIgnoreCase("on");

    btitle = RegexStrUtil.goodStr(btitle);
    /**
     *   update blob stream
     */
    if (getDaoMapper() == null) {
        return handleError("DaoMapper is null in edit photos for login " + login);
    }

    CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON);
    if (carryonDao == null) {
        return handleError("carryonDao is null in edit photos for login " + login);
    }

    String loginId = null;
    if (loginInfo != null) {
        loginId = loginInfo.getValue(DbConstants.LOGIN_ID);
    }

    if (!RegexStrUtil.isNull(caption)) {
        if (caption.length() > GlobalConst.refererSize) {
            caption = caption.substring(0, GlobalConst.refererSize);
        }
        caption = RegexStrUtil.goodText(caption);
    }
    if (!RegexStrUtil.isNull(zoom)) {
        zoom = RegexStrUtil.goodNameStr(zoom);
    }

    try {
        carryonDao.updateCaption(RegexStrUtil.goodText(btitle), zoom, RegexStrUtil.goodNameStr(entryid),
                loginId, RegexStrUtil.goodNameStr(category), login, def, usertags, caption);
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in updateCaption in carryon for login" + login, e);
    }

    /**
     *  retrieve the update blob stream and other blobs
     */
    List carryon = null;
    HashSet tagSet = null;
    try {
        carryon = carryonDao.getCarryonByCategory(loginId, category, DbConstants.READ_FROM_MASTER);
        List tagList = carryonDao.getTags(loginId, DbConstants.READ_FROM_MASTER);
        tagSet = carryonDao.getUniqueTags(tagList);
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in getCarryon() in carryon edit for login " + login, e);
    }

    if (carryon == null) {
        return handleError("carryon is null.");
    } else {
        for (int i = 0; i < carryon.size(); i++) {
            Photo photo = (Photo) carryon.get(i);
            String keywords = photo.getValue(DbConstants.USER_TAGS);

        }
    }

    /*
     * display information about the files.
     */
    DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE);
    if (displayDao == null) {
        return handleError("displayDao is null in carryon edit for login " + login);
    }
    Displaypage displaypage = null;
    try {
        displaypage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_SLAVE);
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in getCarryon() in carryon edit for login " + login, e);
    }

    CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND);
    if (cobrandDao == null) {
        return handleUserpageError("CobrandDao is null, CaptionupdateController");
    }
    Userpage cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID));

    /**
    * editphotos or editfiles - views resolved to the name of 
    * the jsp using ViewResolver
    */
    String viewName = DbConstants.EDIT_PHOTOS;
    if (isFile) {
        viewName = DbConstants.EDIT_FILES;
    }
    Map myModel = new HashMap();
    myModel.put(viewName, carryon);
    if (tagSet != null) {
        myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString()));
    }
    myModel.put(DbConstants.DISPLAY_PAGE, displaypage);
    myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
    myModel.put(DbConstants.USER_PAGE, userpage);
    myModel.put(DbConstants.VISITOR_PAGE, memberUserpage);
    myModel.put(DbConstants.SHARE_INFO, shareInfo);
    myModel.put(DbConstants.LOGIN_INFO, loginInfo);
    myModel.put(DbConstants.COBRAND, cobrand);
    myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login));
    return new ModelAndView(viewName, "model", myModel);
}

From source file:web.CarryonmediaController.java

/**
 * This method is called by the spring framework. The configuration
 * for this controller to be invoked is based on the pagetype and
 * is set in the urlMapping property in the spring config file.
 *
 * @param request the <code>HttpServletRequest</code>
 * @param response the <code>HttpServletResponse</code>
 * @throws ServletException//  w  ww .  j a va  2  s.c o m
 * @throws IOException
 * @return ModelAndView this instance is returned to spring
 */
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        ModelAndView m = super.handleRequest(request, response);
    } catch (Exception e) {
        return handleError("error in handleRequest", e);
    }

    /**
     * Error checking, don't check for session management 
    * as mini album can be viewed out of session
     */
    if (RegexStrUtil.isNull(login) && RegexStrUtil.isNull(member)) {
        return handleError("Login & member are null, CarryonmediaController");
    }

    String entryid = request.getParameter(DbConstants.ENTRYID);
    if (RegexStrUtil.isNull(entryid)) {
        return handleError("entryid is empty/null, forwarding to userpage of login " + login);
    }
    if (entryid.length() > GlobalConst.entryIdSize) {
        return handleError("entryidSize is > forwarding to userpage of login " + login);
    }

    /**
     *   gets the daomapper
     */
    if (getDaoMapper() == null) {
        return handleError("DaoMapper is null in carryon edit.");
    }

    String pageNum = request.getParameter(DbConstants.PAGE_NUM);
    String published = request.getParameter(DbConstants.PUBLISHED);
    Userpage cobrand = null;

    /**
     *  logged in user, accessing another members files or photos
     *  myself = false 
          *  logged in user, accessing own files or photos, 
     *  myself = true
     */
    boolean myself = false;
    if (!RegexStrUtil.isNull(login)) {
        if (!RegexStrUtil.isNull(member) && login.equals(member)) {
            myself = true;
        } else {
            if (RegexStrUtil.isNull(member)) {
                myself = true;
            }
        }
    }

    /**
     * display information about the files, if the category !=1 (files)
     */
    Displaypage displayPage = null;
    DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE);
    if (displayDao == null) {
        return handleError("displayDao is null in carryon edit for login " + login);
    }

    boolean displayPhotos, displayFiles;
    displayPhotos = displayFiles = false;

    try {
        if (myself) {
            displayPage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_MASTER);
        } else {
            displayPage = displayDao.getDisplaypage(member, DbConstants.READ_FROM_SLAVE);
        }
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in getDisplaypage(), CarryonmediaController ", e);
    }

    if ((displayPage != null) && (displayPage.getValue(DbConstants.FILES).equals("1"))) {
        displayFiles = true;
    }

    /**
    * DbConstants.FILES
    */
    if (!myself && !displayFiles) {
        return handleError("member does not give access to display files to others" + member);
    }

    CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND);
    if (cobrandDao == null) {
        return handleUserpageError("CobrandDao is null, CarryonmediaController");
    }

    CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON);
    if (carryonDao == null) {
        return handleError("carryonDao is null in carryon edit.");
    }

    Photo photo = null;
    List tagList = null;
    HashSet tagSet = null;
    Hdlogin memberInfo = null;
    try {
        if (myself) {
            if (loginInfo != null) {
                cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID));
                photo = carryonDao.getCarryon(entryid, loginInfo.getValue(DbConstants.LOGIN_ID));
                tagList = carryonDao.getTags(loginInfo.getValue(DbConstants.LOGIN_ID),
                        DbConstants.READ_FROM_SLAVE);
                tagSet = carryonDao.getUniqueTags(tagList);
            }
            memberInfo = loginInfo;
        } else {
            if (!RegexStrUtil.isNull(member)) {
                MemberDao memberDao = (MemberDao) getDaoMapper().getDao(DbConstants.MEMBER);
                if (memberDao == null) {
                    return handleError("memberDao is null in CarryoeditController, for member= " + member);
                }
                memberInfo = memberDao.getMemberInfo(member);
                if (memberInfo != null) {
                    cobrand = cobrandDao.getUserCobrand(memberInfo.getValue(DbConstants.LOGIN_ID));
                    photo = carryonDao.getCarryon(entryid, memberInfo.getValue(DbConstants.LOGIN_ID));
                    tagList = carryonDao.getTags(memberInfo.getValue(DbConstants.LOGIN_ID),
                            DbConstants.READ_FROM_SLAVE);
                    tagSet = carryonDao.getUniqueTags(tagList);
                }
            } else {
                return handleError("Member is null in CarryonmediaController");
            }
        }
    } catch (BaseDaoException e) {
        return handleError("Exception occurred in getCarryon()", e);
    }

    if (photo == null) {
        return handleError("photo is null, CarryonmediaController.");
    }

    Map myModel = new HashMap();
    if (memberInfo != null) {
        myModel.put(DbConstants.MEMBER_INFO, memberInfo);
    }
    if (tagSet != null) {
        myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString()));
    }

    String viewName = DbConstants.MEDIA_CARRYON;
    myModel.put(DbConstants.LOGIN_INFO, loginInfo);
    myModel.put(DbConstants.PHOTO, photo);
    myModel.put(DbConstants.PUBLISHED, published);
    myModel.put(DbConstants.DISPLAY_PAGE, displayPage);
    myModel.put(DbConstants.USER_PAGE, userpage);
    myModel.put(DbConstants.SHARE_INFO, shareInfo);
    myModel.put(DbConstants.VISITOR_PAGE, memberUserpage);
    myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
    myModel.put(DbConstants.COBRAND, cobrand);
    myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login));
    return new ModelAndView(viewName, "model", myModel);
}

From source file:web.SearchphotosController.java

/**
 * This method is called by the spring framework. The configuration
 * for this controller to be invoked is based on the pagetype and
 * is set in the urlMapping property in the spring config file.
 *
 * @param request the <code>HttpServletRequest</code>
 * @param response the <code>HttpServletResponse</code>
 * @throws ServletException/*from   w  w w .j  av  a2 s.  c  o m*/
 * @throws IOException
 * @return ModelAndView this instance is returned to spring
 */
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        ModelAndView m = super.handleRequest(request, response);
    } catch (Exception e) {
        return handleError("error in handleRequest");
    }

    //outOfSession(request, response);

    String searchText = request.getParameter(DbConstants.SEARCH);
    if (RegexStrUtil.isNull(searchText)) {
        Map myModel = new HashMap();
        String viewName = DbConstants.SEARCH;
        myModel.put(DbConstants.LOGIN_INFO, loginInfo);
        myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
        myModel.put(DbConstants.USER_PAGE, userpage);
        myModel.put(DbConstants.SHARE_INFO, shareInfo);
        myModel.put(DbConstants.VISITOR_PAGE, memberUserpage);
        myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login));
        return new ModelAndView(viewName, "model", myModel);
    }
    searchText = RegexStrUtil.goodText(searchText);

    SearchDao searchDao = (SearchDao) daoMapper.getDao(DbConstants.SEARCH);
    if (searchDao == null) {
        return handleError("searchDao is null in SearchphotosController");
    }

    /**
          *  admin can search in any business.
     */
    boolean isBizAware = false;
    String bid = null;
    if (WebUtil.isProductPremiumSubscription()) {
        if (DiaryAdmin.isDiaryAdmin(login)) {
            isBizAware = false;
        } else {
            isBizAware = true;
        }
        if (login != null && userpage != null) {
            bid = userpage.getValue(DbConstants.BID);
        }
    }

    DirectoryDao dirDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY);
    if (dirDao == null) {
        return handleError("dirDao is null in SearchphotosController");
    }

    HashSet photoSet = null;
    CarryonDao carryonDao = (CarryonDao) daoMapper.getDao(DbConstants.CARRYON);
    if (carryonDao == null) {
        return handleError("carryonDao is null in SearchphotosController");
    }

    HashSet tagList = null;
    HashSet dirBlobResult = null;
    List carryonResult = null;
    try {
        if (isBizAware && bid != null) {
            photoSet = searchDao.bizSearchCarryon(DbConstants.READ_FROM_MASTER, searchText, bid, login);
        } else {
            photoSet = searchDao.searchCarryon(DbConstants.READ_FROM_MASTER, searchText);
        }
        if (rbDirectoryExists.equals("1")) {
            HashSet dirTags = searchDao.searchDirectoryBlobs(DbConstants.READ_FROM_SLAVE, searchText);
            if (dirTags != null && dirTags.size() > 0) {
                dirBlobResult = dirDao.getDirBlobsFromTags(dirTags);
            }
        }

        searchDao.addTags(searchText);

        if (photoSet != null) {
            carryonResult = new ArrayList(photoSet);
            tagList = carryonDao.getUniqueTags(carryonResult);
            if (tagList != null) {
                if (tagList.size() < 10) {
                    List hitList = null;
                    if (isBizAware && bid != null) {
                        hitList = carryonDao.getCarryonHitsBizAware(bid, DbConstants.READ_FROM_SLAVE);
                    } else {
                        hitList = carryonDao.getCarryonHits();
                    }
                    HashSet hitSet = carryonDao.getUniqueTags(hitList);
                    if (hitSet != null) {
                        Iterator it1 = hitSet.iterator();
                        for (int i = 0; i < hitSet.size(); i++) {
                            tagList.add((String) it1.next());
                        }
                    }
                } // tagList.size() < 10
            }
        }
    } catch (BaseDaoException e) {
        return handleError("Exception in either searchDirectory" + searchText, e);
    }

    Map myModel = new HashMap();
    String viewName = DbConstants.PHOTOS;

    if (dirBlobResult == null && carryonResult == null) {
        if (tagList != null) {
            viewName = DbConstants.TAGS;
        }
    }
    if (tagList != null) {
        myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagList.toString()));
    }
    myModel.put(DbConstants.TOP_CARRYON, carryonResult);
    myModel.put(DbConstants.TAG_LIST, tagList);
    myModel.put(DbConstants.LOGIN_INFO, loginInfo);
    myModel.put(DbConstants.USER_PAGE, userpage);
    myModel.put(DbConstants.SHARE_INFO, shareInfo);
    myModel.put(DbConstants.VISITOR_PAGE, memberUserpage);
    myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login));
    myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
    if (rbDirectoryExists.equals("1") && dirBlobResult != null) {
        myModel.put(DbConstants.DIR_BLOB, dirBlobResult);
    }
    return new ModelAndView(viewName, "model", myModel);
}

From source file:exm.stc.frontend.ASTWalker.java

private void waitStmt(Context context, SwiftAST tree) throws UserException {
    Wait wait = Wait.fromAST(context, tree);
    ArrayList<Var> waitEvaled = new ArrayList<Var>();
    for (SwiftAST expr : wait.getWaitExprs()) {
        Type waitExprType = TypeChecker.findExprType(context, expr);
        if (Types.isUnion(waitExprType)) {
            // Choose first alternative type
            for (Type alt : UnionType.getAlternatives(waitExprType)) {
                if (Types.canWaitForFinalize(alt)) {
                    waitExprType = alt;/*from   w  w w  .  java  2  s.  c om*/
                    break;
                }
            }
        }
        if (!Types.canWaitForFinalize(waitExprType)) {
            throw new TypeMismatchException(context,
                    "Waiting for type " + waitExprType.typeName() + " is not supported");
        }
        Var res = exprWalker.eval(context, expr, waitExprType, false, null);
        waitEvaled.add(res);
    }

    ArrayList<Var> keepOpenVars = new ArrayList<Var>();
    summariseBranchVariableUsage(context, Arrays.asList(wait.getBlock().getVariableUsage()), keepOpenVars);

    // Quick sanity check to see we're not directly blocking
    // on any arrays written inside
    HashSet<String> waitVarSet = new HashSet<String>(Var.nameList(waitEvaled));
    waitVarSet.retainAll(Var.nameList(keepOpenVars));
    if (waitVarSet.size() > 0) {
        throw new UserException(context, "Deadlock in wait statement. The following arrays are written "
                + "inside the body of the wait: " + waitVarSet.toString());
    }

    backend.startWaitStatement(context.getFunctionContext().constructName("explicit-wait"),
            VarRepr.backendVars(waitEvaled), WaitMode.WAIT_ONLY, true, wait.isDeepWait(),
            ExecTarget.nonDispatchedControl());
    block(LocalContext.fnSubcontext(context), wait.getBlock());
    backend.endWaitStatement();
}

From source file:com.vmware.bdd.manager.ClusterManager.java

private void checkExtraRequiredPackages() {
    logger.info("check if extra required packages(mailx and wsdl4j) have been installed for Ironfan.");
    if (!extraPackagesExisted) {
        File yumRepoPath = new File(Constants.SERENGETI_YUM_REPO_PATH);

        // use hs to record the packages that have not been added
        final HashSet<String> hs = new HashSet<String>();
        hs.addAll(extraRequiredPackages);

        // scan the files under the serengeti yum repo directory
        File[] rpmList = yumRepoPath.listFiles(new FileFilter() {
            @Override/*from  w ww  .jav  a2 s . c o  m*/
            public boolean accept(File f) {
                String fname = f.getName();
                int idx = fname.indexOf("-");

                if (idx > 0) {
                    String packName = fname.substring(0, idx);
                    if (extraRequiredPackages.contains(packName)) {
                        String regx = packName + commRegex;
                        Pattern pat = Pattern.compile(regx);
                        if (pat.matcher(fname).matches()) {
                            hs.remove(packName);
                            return true;
                        }
                    }
                }
                return false;
            }
        });

        if (!hs.isEmpty()) {
            logger.info("cannot find all the needed packages, stop and return error now. ");
            throw BddException.EXTRA_PACKAGES_NOT_FOUND(hs.toString());
        }

        logger.info("the check is successful: all needed packages are there.");
        extraPackagesExisted = true;
    }
}

From source file:dao.DirectoryAuthorDaoDb.java

/**
 * Given a directoryid, returns HashSet of authors
 * @param directoryId the id of the directory
 * @param userId administrator of directory
 * @param userLogin administrator's login of directory
 * @param accessFlag access Flag//  w  w w.  ja  v a2 s  . c o m
 * @return HashSet - list of authors with the login and member name
 * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
 */
public HashSet listAuthorsOfDirectory(String directoryId, String userId, String userLogin, int accessFlag) {

    if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) {
        throw new BaseDaoException("params are null");
    }

    /**
          *  check user permissions
          */
    if (!diaryAdmin.isDiaryAdmin(userLogin) && !isAuthor(directoryId, userId)) {
        throw new BaseDaoException(
                "User does not have permission to list authors, " + directoryId + " userId = " + userId);
    }

    Fqn fqn = cacheUtil.fqn(DbConstants.DIR_AUTHORS);
    Object obj = treeCache.get(fqn, directoryId);
    if (obj != null) {
        return (HashSet) obj;
    }

    /**
     *  Get scalability datasource for directory, diradmin, 
     *  hdlogin not partitioned
     */
    String sourceName = scalabilityManager.getReadZeroScalability();
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds null, listAuthors() " + sourceName + " userId = " + userId);
    }

    HashSet myResult = null;
    Connection conn = null;
    try {
        conn = ds.getConnection();
        myResult = listAuthorQuery.run(conn, directoryId);
    } catch (Exception e) {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e1) {
            throw new BaseDaoException(
                    "error while listing author query, conn.close()exception in listAuthorQuery " + userLogin,
                    e1);
        }
        throw new BaseDaoException("exception in list authors, " + userLogin, e);
    }

    try {
        if (conn != null) {
            conn.close();
        }
    } catch (Exception e2) {
        throw new BaseDaoException("conn.close exception after completing listAuthorQuery " + userLogin, e2);
    }

    if ((myResult != null) && (!myResult.isEmpty())) {
        treeCache.put(fqn, directoryId, myResult);
    }
    logger.info("myResult = " + myResult.toString());
    return myResult;
}