001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.exception.NoSuchRepositoryEntryException;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.model.RepositoryEntry;
020    import com.liferay.portal.model.User;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.service.base.RepositoryEntryLocalServiceBaseImpl;
023    
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Michael C. Han
029     * @author Mate Thurzo
030     */
031    public class RepositoryEntryLocalServiceImpl
032            extends RepositoryEntryLocalServiceBaseImpl {
033    
034            @Override
035            public RepositoryEntry addRepositoryEntry(
036                            long userId, long groupId, long repositoryId, String mappedId,
037                            ServiceContext serviceContext)
038                    throws PortalException {
039    
040                    User user = userPersistence.findByPrimaryKey(userId);
041    
042                    long repositoryEntryId = counterLocalService.increment();
043    
044                    RepositoryEntry repositoryEntry = repositoryEntryPersistence.create(
045                            repositoryEntryId);
046    
047                    repositoryEntry.setUuid(serviceContext.getUuid());
048                    repositoryEntry.setGroupId(groupId);
049                    repositoryEntry.setCompanyId(user.getCompanyId());
050                    repositoryEntry.setUserId(userId);
051                    repositoryEntry.setUserName(user.getFullName());
052                    repositoryEntry.setRepositoryId(repositoryId);
053                    repositoryEntry.setMappedId(mappedId);
054    
055                    repositoryEntryPersistence.update(repositoryEntry);
056    
057                    return repositoryEntry;
058            }
059    
060            @Override
061            public void deleteRepositoryEntries(
062                            long repositoryId, Iterable<String> mappedIds)
063                    throws PortalException {
064    
065                    for (String mappedId : mappedIds) {
066                            try {
067                                    deleteRepositoryEntry(repositoryId, mappedId);
068                            }
069                            catch (NoSuchRepositoryEntryException nsree) {
070                            }
071                    }
072            }
073    
074            @Override
075            public void deleteRepositoryEntry(long repositoryId, String mappedId)
076                    throws PortalException {
077    
078                    repositoryEntryPersistence.removeByR_M(repositoryId, mappedId);
079            }
080    
081            @Override
082            public List<RepositoryEntry> getRepositoryEntries(long repositoryId) {
083                    return repositoryEntryPersistence.findByRepositoryId(repositoryId);
084            }
085    
086            @Override
087            public RepositoryEntry getRepositoryEntry(
088                            long userId, long groupId, long repositoryId, String objectId)
089                    throws PortalException {
090    
091                    RepositoryEntry repositoryEntry = repositoryEntryPersistence.fetchByR_M(
092                            repositoryId, objectId);
093    
094                    if (repositoryEntry != null) {
095                            return repositoryEntry;
096                    }
097    
098                    return addRepositoryEntry(
099                            userId, groupId, repositoryId, objectId, new ServiceContext());
100            }
101    
102            @Override
103            public RepositoryEntry getRepositoryEntry(String uuid, long groupId)
104                    throws PortalException {
105    
106                    return repositoryEntryPersistence.findByUUID_G(uuid, groupId);
107            }
108    
109            @Override
110            public RepositoryEntry updateRepositoryEntry(
111                            long repositoryEntryId, String mappedId)
112                    throws PortalException {
113    
114                    RepositoryEntry repositoryEntry =
115                            repositoryEntryPersistence.findByPrimaryKey(repositoryEntryId);
116    
117                    repositoryEntry.setMappedId(mappedId);
118    
119                    repositoryEntryPersistence.update(repositoryEntry);
120    
121                    return repositoryEntry;
122            }
123    
124    }