This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.rest.services;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020
021import org.apache.archiva.admin.model.RepositoryAdminException;
022import org.apache.archiva.admin.model.beans.RepositoryGroup;
023import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
024import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
025import org.apache.archiva.rest.api.services.RepositoryGroupService;
026import org.apache.commons.lang3.StringUtils;
027import org.springframework.stereotype.Service;
028
029import javax.inject.Inject;
030import java.util.ArrayList;
031import java.util.List;
032
033/**
034 * @author Olivier Lamy
035 */
036@Service("repositoryGroupService#rest")
037public class DefaultRepositoryGroupService
038    extends AbstractRestService
039    implements RepositoryGroupService
040{
041
042    @Inject
043    private RepositoryGroupAdmin repositoryGroupAdmin;
044
045    @Override
046    public List<RepositoryGroup> getRepositoriesGroups()
047        throws ArchivaRestServiceException
048    {
049        try
050        {
051            List<RepositoryGroup> repositoriesGroups =
052                new ArrayList<>( repositoryGroupAdmin.getRepositoriesGroups().size() );
053            for ( org.apache.archiva.admin.model.beans.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() )
054            {
055                repositoriesGroups.add( new RepositoryGroup( repoGroup.getId(), new ArrayList<>(
056                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ).mergedIndexTtl(
057                    repoGroup.getMergedIndexTtl() ).cronExpression( repoGroup.getCronExpression() ) );
058            }
059            return repositoriesGroups;
060        }
061        catch ( RepositoryAdminException e )
062        {
063            throw new ArchivaRestServiceException( e.getMessage(), e );
064        }
065    }
066
067    @Override
068    public RepositoryGroup getRepositoryGroup( String repositoryGroupId )
069        throws ArchivaRestServiceException
070    {
071        for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() )
072        {
073            if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) )
074            {
075                return repositoryGroup;
076            }
077        }
078        return null;
079    }
080
081    @Override
082    public Boolean addRepositoryGroup( RepositoryGroup repoGroup )
083        throws ArchivaRestServiceException
084    {
085        try
086        {
087            return repositoryGroupAdmin.addRepositoryGroup(
088                new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<>(
089                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ).mergedIndexTtl(
090                    repoGroup.getMergedIndexTtl() ).cronExpression( repoGroup.getCronExpression() ),
091                getAuditInformation() );
092        }
093        catch ( RepositoryAdminException e )
094        {
095            throw new ArchivaRestServiceException( e.getMessage(), e );
096        }
097    }
098
099    @Override
100    public Boolean updateRepositoryGroup( RepositoryGroup repoGroup )
101        throws ArchivaRestServiceException
102    {
103        try
104        {
105            return repositoryGroupAdmin.updateRepositoryGroup(
106                new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<>(
107                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ).mergedIndexTtl(
108                    repoGroup.getMergedIndexTtl() ).cronExpression( repoGroup.getCronExpression() ),
109                getAuditInformation() );
110        }
111        catch ( RepositoryAdminException e )
112        {
113            throw new ArchivaRestServiceException( e.getMessage(), e );
114        }
115    }
116
117    @Override
118    public Boolean deleteRepositoryGroup( String repositoryGroupId )
119        throws ArchivaRestServiceException
120    {
121        try
122        {
123            return repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation() );
124        }
125        catch ( RepositoryAdminException e )
126        {
127            throw new ArchivaRestServiceException( e.getMessage(), e );
128        }
129    }
130
131    @Override
132    public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId )
133        throws ArchivaRestServiceException
134    {
135        try
136        {
137            return repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation() );
138        }
139        catch ( RepositoryAdminException e )
140        {
141            throw new ArchivaRestServiceException( e.getMessage(), e );
142        }
143    }
144
145    @Override
146    public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId )
147        throws ArchivaRestServiceException
148    {
149        try
150        {
151            return repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId,
152                                                                   getAuditInformation() );
153        }
154        catch ( RepositoryAdminException e )
155        {
156            throw new ArchivaRestServiceException( e.getMessage(), e );
157        }
158    }
159}