You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/07/05 22:43:58 UTC
svn commit: r1357890 - in
/archiva/trunk/archiva-modules/archiva-web/archiva-rest:
archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/
archiva-rest-services/src/main/java/org/apache/archiva/rest/services/
Author: olamy
Date: Thu Jul 5 20:43:58 2012
New Revision: 1357890
URL: http://svn.apache.org/viewvc?rev=1357890&view=rev
Log:
oups missed some add files
Added:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ReportRepositoriesService.java (with props)
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultReportRepositoriesService.java (with props)
Added: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ReportRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ReportRepositoriesService.java?rev=1357890&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ReportRepositoriesService.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ReportRepositoriesService.java Thu Jul 5 20:43:58 2012
@@ -0,0 +1,62 @@
+package org.apache.archiva.rest.api.services;
+
+/*
+ * Copyright 2012 Zenika
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
+import org.apache.archiva.redback.authorization.RedbackAuthorization;
+import org.apache.archiva.reports.RepositoryProblemFacet;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * ReportRepositoriesService
+ *
+ * @author Adrien Lecharpentier <ad...@zenika.com>
+ * @since 1.4-M3
+ */
+@Path( "/reportServices/" )
+public interface ReportRepositoriesService
+{
+
+ @Path( "getStatisticsReport" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ public List<RepositoryStatistics> getStatisticsReport( @QueryParam( "repository" ) List<String> repositoriesId,
+ @QueryParam( "rowCount" ) int rowCount,
+ @QueryParam( "startDate" ) Date startDate,
+ @QueryParam( "endDate" ) Date endDate )
+ throws ArchivaRestServiceException;
+
+ @Path( "getHealthReports/{repository}/{rowCount}" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ public List<RepositoryProblemFacet> getHealthReport( @PathParam( "repository" ) String repository,
+ @QueryParam( "groupId" ) String groupId,
+ @PathParam( "rowCount" ) int rowCount )
+ throws ArchivaRestServiceException;
+
+}
Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ReportRepositoriesService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ReportRepositoriesService.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultReportRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultReportRepositoriesService.java?rev=1357890&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultReportRepositoriesService.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultReportRepositoriesService.java Thu Jul 5 20:43:58 2012
@@ -0,0 +1,172 @@
+package org.apache.archiva.rest.services;
+
+/*
+ * Copyright 2012 Zenika
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
+import org.apache.archiva.reports.RepositoryProblemFacet;
+import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
+import org.apache.archiva.rest.api.services.ReportRepositoriesService;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * DefaultReportRepositoriesService
+ *
+ * @author Adrien Lecharpentier <ad...@zenika.com>
+ * @since 1.4-M3
+ */
+@Service( "reportRepositoriesService#rest" )
+public class DefaultReportRepositoriesService
+ extends AbstractRestService
+ implements ReportRepositoriesService
+{
+
+ private static final String ALL_REPOSITORIES = "all";
+
+ @Inject
+ private RepositoryStatisticsManager repositoryStatisticsManager;
+
+ public List<RepositoryStatistics> getStatisticsReport( List<String> repositoriesId, int rowCount, Date startDate,
+ Date endDate )
+ throws ArchivaRestServiceException
+ {
+ switch ( repositoriesId.size() )
+ {
+ case 0:
+ throw new ArchivaRestServiceException( "report.statistics.report.missing-repositories", null );
+ case 1:
+ return getUniqueRepositoryReport( repositoriesId.get( 0 ), rowCount, startDate, endDate );
+ default:
+ return getMultipleRepositoriesReport( repositoriesId, rowCount );
+ }
+ }
+
+ private List<RepositoryStatistics> getMultipleRepositoriesReport( List<String> repositoriesId, int rowCount )
+ {
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
+ try
+ {
+ MetadataRepository metadataRepository = repositorySession.getRepository();
+ List<RepositoryStatistics> stats = new ArrayList<RepositoryStatistics>();
+ for ( String repo : repositoriesId )
+ {
+ try
+ {
+ stats.add( repositoryStatisticsManager.getLastStatistics( metadataRepository, repo ) );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e );
+ }
+ }
+
+ return stats.subList( 0, stats.size() > rowCount ? rowCount : stats.size() );
+ }
+ finally
+ {
+ repositorySession.close();
+ }
+ }
+
+ private List<RepositoryStatistics> getUniqueRepositoryReport( String repositoryId, int rowCount, Date startDate,
+ Date endDate )
+ {
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
+ try
+ {
+ MetadataRepository metadataRepository = repositorySession.getRepository();
+ List<RepositoryStatistics> stats = null;
+ try
+ {
+ stats = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, repositoryId, startDate,
+ endDate );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e );
+ }
+ if ( stats == null || stats.isEmpty() )
+ {
+ return Collections.<RepositoryStatistics>emptyList();
+ }
+
+ return stats.subList( 0, stats.size() > rowCount ? rowCount : stats.size() );
+ }
+ finally
+ {
+ repositorySession.close();
+ }
+ }
+
+ public List<RepositoryProblemFacet> getHealthReport( String repository, String groupId, int rowCount )
+ throws ArchivaRestServiceException
+ {
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
+ try
+ {
+ List<String> observableRepositories = getObservableRepos();
+ if ( !ALL_REPOSITORIES.equals( repository ) && !observableRepositories.contains( repository ) )
+ {
+ throw new ArchivaRestServiceException(
+ "${$.i18n.prop('report.repository.illegal-access', " + repository + ")}", "repositoryId",
+ new IllegalAccessException() );
+ }
+
+ if ( !ALL_REPOSITORIES.equals( repository ) )
+ {
+ observableRepositories = Collections.<String>singletonList( repository );
+ }
+
+ List<RepositoryProblemFacet> problemArtifacts = new ArrayList<RepositoryProblemFacet>();
+ MetadataRepository metadataRepository = repositorySession.getRepository();
+ for ( String repoId : observableRepositories )
+ {
+ for ( String name : metadataRepository.getMetadataFacets( repoId, RepositoryProblemFacet.FACET_ID ) )
+ {
+ RepositoryProblemFacet metadataFacet =
+ (RepositoryProblemFacet) metadataRepository.getMetadataFacet( repoId,
+ RepositoryProblemFacet.FACET_ID,
+ name );
+ if ( StringUtils.isEmpty( groupId ) || groupId.equals( metadataFacet.getNamespace() ) )
+ {
+ problemArtifacts.add( metadataFacet );
+ }
+ }
+ }
+
+ return problemArtifacts;
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(), e );
+ }
+ finally
+ {
+ repositorySession.close();
+ }
+ }
+}
Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultReportRepositoriesService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultReportRepositoriesService.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Re: svn commit: r1357890
Posted by Brett Porter <br...@apache.org>.
On 06/07/2012, at 7:33 PM, Adrien Lecharpentier wrote:
> Hello,
>
> Ok, this is my mistake. I'm making the new patch with some tests fixe from
> the original patch.
Thanks - is much appreciated!
>
> --
> Adrien Lecharpentier
>
>
> 2012/7/6 Brett Porter <br...@apache.org>
>
>>
>> On 06/07/2012, at 7:15 PM, Olivier Lamy wrote:
>>
>>> I understand the company copyright issue.
>>> But if I read that http://www.apache.org/licenses/LICENSE-2.0#apply
>>> There is a Copyright [yyyy] [name of copyright owner]
>>> ??
>>
>> That describes how another projects using the Apache License should apply
>> the headers. For code contributed to the ASF, this is the policy:
>> http://www.apache.org/legal/src-headers.html
>>
>> In particular:
>> --
>> If the source file is submitted with a copyright notice included in it,
>> the copyright owner (or owner's agent) must either:
>> • remove such notices, or
>> • move them to the NOTICE file associated with each applicable
>> project release, or
>> • provide written permission for the ASF to make such removal or
>> relocation of the notices.
>> --
>>
>> Having permission to remove the header below avoids us having to maintain
>> the duplicate.
>>
>> - Brett
>>
>>
>>>
>>> 2012/7/6 Olivier Lamy <ol...@apache.org>:
>>>> Ouch yes sorry I didn't check that !!
>>>> My bad.
>>>> I will.
>>>>
>>>> 2012/7/6 Brett Porter <br...@apache.org>:
>>>>>
>>>>> On 06/07/2012, at 6:43 AM, olamy@apache.org wrote:
>>>>>
>>>>>> +/*
>>>>>> + * Copyright 2012 Zenika
>>>>>> + *
>>>>>> + * Licensed under the Apache License, Version 2.0 (the "License");
>>>>>> + * you may not use this file except in compliance with the License.
>>>>>> + * You may obtain a copy of the License at
>>>>>> + *
>>>>>> + * http://www.apache.org/licenses/LICENSE-2.0
>>>>>> + *
>>>>>> + * Unless required by applicable law or agreed to in writing,
>> software
>>>>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>>>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>> implied.
>>>>>> + * See the License for the specific language governing permissions
>> and
>>>>>> + * limitations under the License.
>>>>>> + */
>>>>>
>>>>> Can we request the submitter replace these license headers?
>>>>>
>>>>> - Brett
>>
>>
>>
>>
>>
>>
>>
--
Brett Porter
brett@apache.org
http://brettporter.wordpress.com/
Re: svn commit: r1357890
Posted by Adrien Lecharpentier <ad...@gmail.com>.
Hello,
Ok, this is my mistake. I'm making the new patch with some tests fixe from
the original patch.
--
Adrien Lecharpentier
2012/7/6 Brett Porter <br...@apache.org>
>
> On 06/07/2012, at 7:15 PM, Olivier Lamy wrote:
>
> > I understand the company copyright issue.
> > But if I read that http://www.apache.org/licenses/LICENSE-2.0#apply
> > There is a Copyright [yyyy] [name of copyright owner]
> > ??
>
> That describes how another projects using the Apache License should apply
> the headers. For code contributed to the ASF, this is the policy:
> http://www.apache.org/legal/src-headers.html
>
> In particular:
> --
> If the source file is submitted with a copyright notice included in it,
> the copyright owner (or owner's agent) must either:
> • remove such notices, or
> • move them to the NOTICE file associated with each applicable
> project release, or
> • provide written permission for the ASF to make such removal or
> relocation of the notices.
> --
>
> Having permission to remove the header below avoids us having to maintain
> the duplicate.
>
> - Brett
>
>
> >
> > 2012/7/6 Olivier Lamy <ol...@apache.org>:
> >> Ouch yes sorry I didn't check that !!
> >> My bad.
> >> I will.
> >>
> >> 2012/7/6 Brett Porter <br...@apache.org>:
> >>>
> >>> On 06/07/2012, at 6:43 AM, olamy@apache.org wrote:
> >>>
> >>>> +/*
> >>>> + * Copyright 2012 Zenika
> >>>> + *
> >>>> + * Licensed under the Apache License, Version 2.0 (the "License");
> >>>> + * you may not use this file except in compliance with the License.
> >>>> + * You may obtain a copy of the License at
> >>>> + *
> >>>> + * http://www.apache.org/licenses/LICENSE-2.0
> >>>> + *
> >>>> + * Unless required by applicable law or agreed to in writing,
> software
> >>>> + * distributed under the License is distributed on an "AS IS" BASIS,
> >>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> >>>> + * See the License for the specific language governing permissions
> and
> >>>> + * limitations under the License.
> >>>> + */
> >>>
> >>> Can we request the submitter replace these license headers?
> >>>
> >>> - Brett
>
>
>
>
>
>
>
Re: svn commit: r1357890
Posted by Brett Porter <br...@apache.org>.
On 06/07/2012, at 7:15 PM, Olivier Lamy wrote:
> I understand the company copyright issue.
> But if I read that http://www.apache.org/licenses/LICENSE-2.0#apply
> There is a Copyright [yyyy] [name of copyright owner]
> ??
That describes how another projects using the Apache License should apply the headers. For code contributed to the ASF, this is the policy: http://www.apache.org/legal/src-headers.html
In particular:
--
If the source file is submitted with a copyright notice included in it, the copyright owner (or owner's agent) must either:
• remove such notices, or
• move them to the NOTICE file associated with each applicable project release, or
• provide written permission for the ASF to make such removal or relocation of the notices.
--
Having permission to remove the header below avoids us having to maintain the duplicate.
- Brett
>
> 2012/7/6 Olivier Lamy <ol...@apache.org>:
>> Ouch yes sorry I didn't check that !!
>> My bad.
>> I will.
>>
>> 2012/7/6 Brett Porter <br...@apache.org>:
>>>
>>> On 06/07/2012, at 6:43 AM, olamy@apache.org wrote:
>>>
>>>> +/*
>>>> + * Copyright 2012 Zenika
>>>> + *
>>>> + * Licensed under the Apache License, Version 2.0 (the "License");
>>>> + * you may not use this file except in compliance with the License.
>>>> + * You may obtain a copy of the License at
>>>> + *
>>>> + * http://www.apache.org/licenses/LICENSE-2.0
>>>> + *
>>>> + * Unless required by applicable law or agreed to in writing, software
>>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>>> + * See the License for the specific language governing permissions and
>>>> + * limitations under the License.
>>>> + */
>>>
>>> Can we request the submitter replace these license headers?
>>>
>>> - Brett
Re: svn commit: r1357890
Posted by Olivier Lamy <ol...@apache.org>.
I understand the company copyright issue.
But if I read that http://www.apache.org/licenses/LICENSE-2.0#apply
There is a Copyright [yyyy] [name of copyright owner]
??
2012/7/6 Olivier Lamy <ol...@apache.org>:
> Ouch yes sorry I didn't check that !!
> My bad.
> I will.
>
> 2012/7/6 Brett Porter <br...@apache.org>:
>>
>> On 06/07/2012, at 6:43 AM, olamy@apache.org wrote:
>>
>>> +/*
>>> + * Copyright 2012 Zenika
>>> + *
>>> + * Licensed under the Apache License, Version 2.0 (the "License");
>>> + * you may not use this file except in compliance with the License.
>>> + * You may obtain a copy of the License at
>>> + *
>>> + * http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing, software
>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>> + * See the License for the specific language governing permissions and
>>> + * limitations under the License.
>>> + */
>>
>> Can we request the submitter replace these license headers?
>>
>> - Brett
>>
>> --
>> Brett Porter
>> brett@apache.org
>> http://brettporter.wordpress.com/
>> http://au.linkedin.com/in/brettporter
>> http://twitter.com/brettporter
>>
>>
>>
>>
>>
>
>
>
> --
> Olivier Lamy
> Talend: http://coders.talend.com
> http://twitter.com/olamy | http://linkedin.com/in/olamy
--
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy
Re: svn commit: r1357890
Posted by Olivier Lamy <ol...@apache.org>.
Ouch yes sorry I didn't check that !!
My bad.
I will.
2012/7/6 Brett Porter <br...@apache.org>:
>
> On 06/07/2012, at 6:43 AM, olamy@apache.org wrote:
>
>> +/*
>> + * Copyright 2012 Zenika
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing, software
>> + * distributed under the License is distributed on an "AS IS" BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>> + * See the License for the specific language governing permissions and
>> + * limitations under the License.
>> + */
>
> Can we request the submitter replace these license headers?
>
> - Brett
>
> --
> Brett Porter
> brett@apache.org
> http://brettporter.wordpress.com/
> http://au.linkedin.com/in/brettporter
> http://twitter.com/brettporter
>
>
>
>
>
--
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy
Re: svn commit: r1357890
Posted by Brett Porter <br...@apache.org>.
On 06/07/2012, at 6:43 AM, olamy@apache.org wrote:
> +/*
> + * Copyright 2012 Zenika
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
Can we request the submitter replace these license headers?
- Brett
--
Brett Porter
brett@apache.org
http://brettporter.wordpress.com/
http://au.linkedin.com/in/brettporter
http://twitter.com/brettporter