001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
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.Date;
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Michael C. Han
030     * @author Mate Thurzo
031     */
032    public class RepositoryEntryLocalServiceImpl
033            extends RepositoryEntryLocalServiceBaseImpl {
034    
035            @Override
036            public RepositoryEntry addRepositoryEntry(
037                            long userId, long groupId, long repositoryId, String mappedId,
038                            ServiceContext serviceContext)
039                    throws PortalException, SystemException {
040    
041                    User user = userPersistence.findByPrimaryKey(userId);
042                    Date now = new Date();
043    
044                    long repositoryEntryId = counterLocalService.increment();
045    
046                    RepositoryEntry repositoryEntry = repositoryEntryPersistence.create(
047                            repositoryEntryId);
048    
049                    repositoryEntry.setUuid(serviceContext.getUuid());
050                    repositoryEntry.setGroupId(groupId);
051                    repositoryEntry.setCompanyId(user.getCompanyId());
052                    repositoryEntry.setUserId(userId);
053                    repositoryEntry.setUserName(user.getFullName());
054                    repositoryEntry.setCreateDate(serviceContext.getCreateDate(now));
055                    repositoryEntry.setModifiedDate(serviceContext.getModifiedDate(now));
056                    repositoryEntry.setRepositoryId(repositoryId);
057                    repositoryEntry.setMappedId(mappedId);
058    
059                    repositoryEntryPersistence.update(repositoryEntry);
060    
061                    return repositoryEntry;
062            }
063    
064            @Override
065            public List<RepositoryEntry> getRepositoryEntries(long repositoryId)
066                    throws SystemException {
067    
068                    return repositoryEntryPersistence.findByRepositoryId(repositoryId);
069            }
070    
071            @Override
072            public RepositoryEntry updateRepositoryEntry(
073                            long repositoryEntryId, String mappedId)
074                    throws PortalException, SystemException {
075    
076                    RepositoryEntry repositoryEntry =
077                            repositoryEntryPersistence.findByPrimaryKey(repositoryEntryId);
078    
079                    repositoryEntry.setModifiedDate(new Date());
080                    repositoryEntry.setMappedId(mappedId);
081    
082                    repositoryEntryPersistence.update(repositoryEntry);
083    
084                    return repositoryEntry;
085            }
086    
087    }