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.kernel.exception.PortalException;
018    import com.liferay.portal.model.RepositoryEntry;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portal.service.base.RepositoryEntryLocalServiceBaseImpl;
022    
023    import java.util.Date;
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                    Date now = new Date();
042    
043                    long repositoryEntryId = counterLocalService.increment();
044    
045                    RepositoryEntry repositoryEntry = repositoryEntryPersistence.create(
046                            repositoryEntryId);
047    
048                    repositoryEntry.setUuid(serviceContext.getUuid());
049                    repositoryEntry.setGroupId(groupId);
050                    repositoryEntry.setCompanyId(user.getCompanyId());
051                    repositoryEntry.setUserId(userId);
052                    repositoryEntry.setUserName(user.getFullName());
053                    repositoryEntry.setCreateDate(serviceContext.getCreateDate(now));
054                    repositoryEntry.setModifiedDate(serviceContext.getModifiedDate(now));
055                    repositoryEntry.setRepositoryId(repositoryId);
056                    repositoryEntry.setMappedId(mappedId);
057    
058                    repositoryEntryPersistence.update(repositoryEntry);
059    
060                    return repositoryEntry;
061            }
062    
063            @Override
064            public List<RepositoryEntry> getRepositoryEntries(long repositoryId) {
065                    return repositoryEntryPersistence.findByRepositoryId(repositoryId);
066            }
067    
068            @Override
069            public RepositoryEntry updateRepositoryEntry(
070                            long repositoryEntryId, String mappedId)
071                    throws PortalException {
072    
073                    RepositoryEntry repositoryEntry =
074                            repositoryEntryPersistence.findByPrimaryKey(repositoryEntryId);
075    
076                    repositoryEntry.setModifiedDate(new Date());
077                    repositoryEntry.setMappedId(mappedId);
078    
079                    repositoryEntryPersistence.update(repositoryEntry);
080    
081                    return repositoryEntry;
082            }
083    
084    }