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    
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            public RepositoryEntry addRepositoryEntry(
035                            long userId, long groupId, long repositoryId, String mappedId,
036                            ServiceContext serviceContext)
037                    throws PortalException, SystemException {
038    
039                    User user = userPersistence.findByPrimaryKey(userId);
040                    Date now = new Date();
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.setCreateDate(serviceContext.getCreateDate(now));
053                    repositoryEntry.setModifiedDate(serviceContext.getModifiedDate(now));
054                    repositoryEntry.setRepositoryId(repositoryId);
055                    repositoryEntry.setMappedId(mappedId);
056    
057                    repositoryEntryPersistence.update(repositoryEntry);
058    
059                    return repositoryEntry;
060            }
061    
062            public RepositoryEntry updateRepositoryEntry(
063                            long repositoryEntryId, String mappedId)
064                    throws PortalException, SystemException {
065    
066                    RepositoryEntry repositoryEntry =
067                            repositoryEntryPersistence.findByPrimaryKey(repositoryEntryId);
068    
069                    repositoryEntry.setModifiedDate(new Date());
070                    repositoryEntry.setMappedId(mappedId);
071    
072                    repositoryEntryPersistence.update(repositoryEntry);
073    
074                    return repositoryEntry;
075            }
076    
077    }