Example usage for com.liferay.portal.kernel.util StringPool COMMA

List of usage examples for com.liferay.portal.kernel.util StringPool COMMA

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool COMMA.

Prototype

String COMMA

To view the source code for com.liferay.portal.kernel.util StringPool COMMA.

Click Source Link

Usage

From source file:com.liferay.ams.service.persistence.impl.TypePersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, Type> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*from w  ww .j a v a2  s .c o m*/

    Map<Serializable, Type> map = new HashMap<Serializable, Type>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        Type type = fetchByPrimaryKey(primaryKey);

        if (type != null) {
            map.put(primaryKey, type);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Type type = (Type) EntityCacheUtil.getResult(TypeModelImpl.ENTITY_CACHE_ENABLED, TypeImpl.class,
                primaryKey);

        if (type == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, type);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_TYPE_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (Type type : (List<Type>) q.list()) {
            map.put(type.getPrimaryKeyObj(), type);

            cacheResult(type);

            uncachedPrimaryKeys.remove(type.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(TypeModelImpl.ENTITY_CACHE_ENABLED, TypeImpl.class, primaryKey,
                    _nullType);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.asset.sharing.service.persistence.AssetSharingEntryPK.java

License:Open Source License

@Override
public String toString() {
    StringBundler sb = new StringBundler(20);

    sb.append(StringPool.OPEN_CURLY_BRACE);

    sb.append("classNameId");
    sb.append(StringPool.EQUAL);//from w ww  .  j av  a2s  .  co  m
    sb.append(classNameId);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("classPK");
    sb.append(StringPool.EQUAL);
    sb.append(classPK);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("sharedToClassNameId");
    sb.append(StringPool.EQUAL);
    sb.append(sharedToClassNameId);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("sharedToClassPK");
    sb.append(StringPool.EQUAL);
    sb.append(sharedToClassPK);

    sb.append(StringPool.CLOSE_CURLY_BRACE);

    return sb.toString();
}

From source file:com.liferay.bbb.service.persistence.impl.BBBMeetingPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, BBBMeeting> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from w  ww  .  j  a  va2 s.  co  m

    Map<Serializable, BBBMeeting> map = new HashMap<Serializable, BBBMeeting>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        BBBMeeting bbbMeeting = fetchByPrimaryKey(primaryKey);

        if (bbbMeeting != null) {
            map.put(primaryKey, bbbMeeting);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        BBBMeeting bbbMeeting = (BBBMeeting) EntityCacheUtil.getResult(BBBMeetingModelImpl.ENTITY_CACHE_ENABLED,
                BBBMeetingImpl.class, primaryKey);

        if (bbbMeeting == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, bbbMeeting);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_BBBMEETING_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (BBBMeeting bbbMeeting : (List<BBBMeeting>) q.list()) {
            map.put(bbbMeeting.getPrimaryKeyObj(), bbbMeeting);

            cacheResult(bbbMeeting);

            uncachedPrimaryKeys.remove(bbbMeeting.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(BBBMeetingModelImpl.ENTITY_CACHE_ENABLED, BBBMeetingImpl.class,
                    primaryKey, _nullBBBMeeting);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.bbb.service.persistence.impl.BBBParticipantPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, BBBParticipant> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//  www .jav  a  2  s  .c om

    Map<Serializable, BBBParticipant> map = new HashMap<Serializable, BBBParticipant>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        BBBParticipant bbbParticipant = fetchByPrimaryKey(primaryKey);

        if (bbbParticipant != null) {
            map.put(primaryKey, bbbParticipant);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        BBBParticipant bbbParticipant = (BBBParticipant) EntityCacheUtil
                .getResult(BBBParticipantModelImpl.ENTITY_CACHE_ENABLED, BBBParticipantImpl.class, primaryKey);

        if (bbbParticipant == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, bbbParticipant);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_BBBPARTICIPANT_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (BBBParticipant bbbParticipant : (List<BBBParticipant>) q.list()) {
            map.put(bbbParticipant.getPrimaryKeyObj(), bbbParticipant);

            cacheResult(bbbParticipant);

            uncachedPrimaryKeys.remove(bbbParticipant.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(BBBParticipantModelImpl.ENTITY_CACHE_ENABLED, BBBParticipantImpl.class,
                    primaryKey, _nullBBBParticipant);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.bbb.service.persistence.impl.BBBServerPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, BBBServer> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from w ww.  j ava  2s  .  c  o  m

    Map<Serializable, BBBServer> map = new HashMap<Serializable, BBBServer>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        BBBServer bbbServer = fetchByPrimaryKey(primaryKey);

        if (bbbServer != null) {
            map.put(primaryKey, bbbServer);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        BBBServer bbbServer = (BBBServer) EntityCacheUtil.getResult(BBBServerModelImpl.ENTITY_CACHE_ENABLED,
                BBBServerImpl.class, primaryKey);

        if (bbbServer == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, bbbServer);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_BBBSERVER_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (BBBServer bbbServer : (List<BBBServer>) q.list()) {
            map.put(bbbServer.getPrimaryKeyObj(), bbbServer);

            cacheResult(bbbServer);

            uncachedPrimaryKeys.remove(bbbServer.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(BBBServerModelImpl.ENTITY_CACHE_ENABLED, BBBServerImpl.class, primaryKey,
                    _nullBBBServer);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

protected void pingTrackbacks(BlogsEntry entry, String[] trackbacks, boolean pingOldTrackbacks,
        ServiceContext serviceContext) throws PortalException {

    if (!PropsValues.BLOGS_TRACKBACK_ENABLED || !entry.isAllowTrackbacks() || !entry.isApproved()) {

        return;//w w  w .  j  ava2s  . co  m
    }

    HttpServletRequest request = serviceContext.getRequest();

    if (request == null) {
        return;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String layoutFullURL = PortalUtil.getLayoutFullURL(themeDisplay);

    if (Validator.isNull(layoutFullURL)) {
        return;
    }

    Map<String, String> parts = new HashMap<>();

    String excerpt = StringUtil.shorten(HtmlUtil.extractText(entry.getContent()),
            PropsValues.BLOGS_LINKBACK_EXCERPT_LENGTH);
    String url = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" + entry.getUrlTitle();

    parts.put("title", entry.getTitle());
    parts.put("excerpt", excerpt);
    parts.put("url", url);
    parts.put("blog_name", entry.getUserName());

    Set<String> trackbacksSet = null;

    if (ArrayUtil.isNotEmpty(trackbacks)) {
        trackbacksSet = SetUtil.fromArray(trackbacks);
    } else {
        trackbacksSet = new HashSet<>();
    }

    if (pingOldTrackbacks) {
        trackbacksSet.addAll(SetUtil.fromArray(StringUtil.split(entry.getTrackbacks())));

        entry.setTrackbacks(StringPool.BLANK);

        blogsEntryPersistence.update(entry);
    }

    Set<String> oldTrackbacks = SetUtil.fromArray(StringUtil.split(entry.getTrackbacks()));

    Set<String> validTrackbacks = new HashSet<>();

    for (String trackback : trackbacksSet) {
        if (oldTrackbacks.contains(trackback)) {
            continue;
        }

        try {
            if (LinkbackProducerUtil.sendTrackback(trackback, parts)) {
                validTrackbacks.add(trackback);
            }
        } catch (Exception e) {
            _log.error("Error while sending trackback at " + trackback, e);
        }
    }

    if (!validTrackbacks.isEmpty()) {
        String newTrackbacks = StringUtil.merge(validTrackbacks);

        if (Validator.isNotNull(entry.getTrackbacks())) {
            newTrackbacks += StringPool.COMMA + entry.getTrackbacks();
        }

        entry.setTrackbacks(newTrackbacks);

        blogsEntryPersistence.update(entry);
    }
}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

protected void validate(long smallImageFileEntryId) throws PortalException {
    String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS,
            StringPool.COMMA);

    if (smallImageFileEntryId != 0) {
        FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(smallImageFileEntryId);

        boolean validSmallImageExtension = false;

        for (String imageExtension : imageExtensions) {
            if (StringPool.STAR.equals(imageExtension)
                    || imageExtension.equals(StringPool.PERIOD + fileEntry.getExtension())) {

                validSmallImageExtension = true;

                break;
            }//from ww  w  .jav a2  s.c  o  m
        }

        if (!validSmallImageExtension) {
            throw new EntrySmallImageNameException(
                    "Invalid small image for file entry " + smallImageFileEntryId);
        }
    }
}

From source file:com.liferay.blogs.web.internal.upload.BaseBlogsUploadHandler.java

License:Open Source License

@Override
public void validateFile(String fileName, String contentType, long size) throws PortalException {

    long maxSize = getMaxFileSize();

    if ((maxSize > 0) && (size > maxSize)) {
        throw new EntryImageSizeException();
    }//  w w  w . j  a  v a 2  s.  c  o m

    String extension = FileUtil.getExtension(fileName);

    String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS,
            StringPool.COMMA);

    for (String imageExtension : imageExtensions) {
        if (StringPool.STAR.equals(imageExtension) || imageExtension.equals(StringPool.PERIOD + extension)) {

            return;
        }
    }

    throw new EntryImageNameException("Invalid image for file name " + fileName);
}

From source file:com.liferay.blogs.web.internal.upload.BaseBlogsUploadHandler.java

License:Open Source License

@Override
protected void doHandleUploadException(PortletRequest portletRequest, PortletResponse portletResponse,
        PortalException pe, JSONObject jsonObject) throws PortalException {

    if (pe instanceof EntryImageNameException || pe instanceof EntryImageSizeException) {

        String errorMessage = StringPool.BLANK;
        int errorType = 0;

        if (pe instanceof EntryImageNameException) {
            errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION;

            String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS,
                    StringPool.COMMA);

            errorMessage = StringUtil.merge(imageExtensions);
        } else if (pe instanceof EntryImageSizeException) {
            errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION;
        }/*  ww  w  .j  a  v  a 2s .  c  o  m*/

        JSONObject errorJSONObject = JSONFactoryUtil.createJSONObject();

        errorJSONObject.put("errorType", errorType);
        errorJSONObject.put("message", errorMessage);

        jsonObject.put("error", errorJSONObject);
    } else {
        throw pe;
    }
}

From source file:com.liferay.book.service.persistence.impl.BookPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, Book> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*  w  w  w.j a v  a2 s .c  o m*/

    Map<Serializable, Book> map = new HashMap<Serializable, Book>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        Book book = fetchByPrimaryKey(primaryKey);

        if (book != null) {
            map.put(primaryKey, book);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(BookModelImpl.ENTITY_CACHE_ENABLED, BookImpl.class,
                primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (Book) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_BOOK_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (Book book : (List<Book>) q.list()) {
            map.put(book.getPrimaryKeyObj(), book);

            cacheResult(book);

            uncachedPrimaryKeys.remove(book.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(BookModelImpl.ENTITY_CACHE_ENABLED, BookImpl.class, primaryKey, nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}