001    /**
002     * Copyright (c) 2000-2013 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.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    }