import javax.annotation.PostConstruct; | import javax.annotation.PostConstruct; | ||||
import javax.inject.Inject; | import javax.inject.Inject; | ||||
import javax.inject.Named; | import javax.inject.Named; | ||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.List; | import java.util.List; | ||||
@Inject | @Inject | ||||
private FileTypes filetypes; | private FileTypes filetypes; | ||||
private Date whenGathered; | |||||
private ZonedDateTime whenGathered; | |||||
private List<String> includes = new ArrayList<>( 0 ); | private List<String> includes = new ArrayList<>( 0 ); | ||||
throws ConsumerException | throws ConsumerException | ||||
{ | { | ||||
repoId = repo.getId(); | repoId = repo.getId(); | ||||
this.whenGathered = whenGathered; | |||||
this.whenGathered = ZonedDateTime.ofInstant(whenGathered.toInstant(), ZoneId.of("GMT")); | |||||
} | } | ||||
@Override | @Override |
import java.nio.channels.Channels; | import java.nio.channels.Channels; | ||||
import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||
import java.nio.file.NoSuchFileException; | import java.nio.file.NoSuchFileException; | ||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | |||||
import java.util.*; | import java.util.*; | ||||
import java.util.function.Predicate; | import java.util.function.Predicate; | ||||
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
} | } | ||||
private static void populateArtifactMetadataFromFile(ArtifactMetadata metadata, StorageAsset file) throws IOException { | private static void populateArtifactMetadataFromFile(ArtifactMetadata metadata, StorageAsset file) throws IOException { | ||||
metadata.setWhenGathered(new Date()); | |||||
metadata.setWhenGathered(ZonedDateTime.now(ZoneId.of("GMT"))); | |||||
metadata.setFileLastModified(file.getModificationTime().toEpochMilli()); | metadata.setFileLastModified(file.getModificationTime().toEpochMilli()); | ||||
ChecksummedFile checksummedFile = new ChecksummedFile(file.getFilePath()); | ChecksummedFile checksummedFile = new ChecksummedFile(file.getFilePath()); | ||||
try { | try { |
throws FeedException | throws FeedException | ||||
{ | { | ||||
ZonedDateTime greaterThanThisDate = ZonedDateTime.of(LocalDateTime.now(), GMT_TIME_ZONE.toZoneId()).minusDays( | |||||
ZonedDateTime greaterThanThisDate = ZonedDateTime.now(GMT_TIME_ZONE.toZoneId()).minusDays( | |||||
getNumberOfDaysBeforeNow() | getNumberOfDaysBeforeNow() | ||||
).truncatedTo(ChronoUnit.SECONDS); | ).truncatedTo(ChronoUnit.SECONDS); | ||||
List<ArtifactMetadata> artifacts; | List<ArtifactMetadata> artifacts; | ||||
int idx = 0; | int idx = 0; | ||||
for ( ArtifactMetadata artifact : artifacts ) | for ( ArtifactMetadata artifact : artifacts ) | ||||
{ | { | ||||
long whenGathered = artifact.getWhenGathered().getTime(); | |||||
long whenGathered = artifact.getWhenGathered().toInstant().toEpochMilli(); | |||||
String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId(); | String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId(); | ||||
if ( tmp != whenGathered ) | if ( tmp != whenGathered ) | ||||
String repoId1 = artifact.getRepositoryId(); | String repoId1 = artifact.getRepositoryId(); | ||||
entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date( | entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date( | ||||
whenGathered ) ); | whenGathered ) ); | ||||
entry.setPublishedDate( artifact.getWhenGathered() ); | |||||
entry.setPublishedDate( Date.from(artifact.getWhenGathered().toInstant()) ); | |||||
description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | "; | description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | "; | ||||
} | } | ||||
else | else |
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import javax.inject.Inject; | import javax.inject.Inject; | ||||
import java.time.ZoneId; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.Date; | import java.util.Date; | ||||
int idx = 0; | int idx = 0; | ||||
for ( ArtifactMetadata artifact : artifacts ) | for ( ArtifactMetadata artifact : artifacts ) | ||||
{ | { | ||||
long whenGathered = artifact.getWhenGathered().getTime(); | |||||
long whenGathered = artifact.getWhenGathered().toInstant().toEpochMilli(); | |||||
if ( tmp != whenGathered ) | if ( tmp != whenGathered ) | ||||
{ | { | ||||
entry = new RssFeedEntry( | entry = new RssFeedEntry( | ||||
this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) ); | this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) ); | ||||
entry.setPublishedDate( artifact.getWhenGathered() ); | |||||
entry.setPublishedDate( Date.from(artifact.getWhenGathered().toInstant()) ); | |||||
description = | description = | ||||
this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() + | this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() + | ||||
" | "; | " | "; |
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||
import java.time.LocalDateTime; | |||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | import java.time.ZonedDateTime; | ||||
import java.time.temporal.ChronoUnit; | import java.time.temporal.ChronoUnit; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
throws Exception | throws Exception | ||||
{ | { | ||||
List<ArtifactMetadata> newArtifacts = new ArrayList<>(); | List<ArtifactMetadata> newArtifacts = new ArrayList<>(); | ||||
Date whenGathered = Calendar.getInstance().getTime(); | |||||
ZonedDateTime whenGathered = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()); | |||||
newArtifacts.add( createArtifact( "artifact-one", "1.0", whenGathered ) ); | newArtifacts.add( createArtifact( "artifact-one", "1.0", whenGathered ) ); | ||||
newArtifacts.add( createArtifact( "artifact-one", "1.1", whenGathered ) ); | newArtifacts.add( createArtifact( "artifact-one", "1.1", whenGathered ) ); | ||||
SyndFeed feed = newArtifactsProcessor.process( reqParams ); | SyndFeed feed = newArtifactsProcessor.process( reqParams ); | ||||
// check that the date used in the call is close to the one passed (5 seconds difference at most) | // check that the date used in the call is close to the one passed (5 seconds difference at most) | ||||
Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) ); | |||||
cal.add( Calendar.DATE, -30 ); | |||||
assertTrue( metadataRepository.getFrom().minus(cal.getTimeInMillis(), ChronoUnit.MILLIS).toInstant().toEpochMilli() < 1000 * 5 ); | |||||
ZonedDateTime cal = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).minusDays(30); | |||||
assertTrue(ChronoUnit.SECONDS.between(cal.toInstant(), metadataRepository.getFrom().toInstant())<5); | |||||
assertEquals( null, metadataRepository.getTo() ); | assertEquals( null, metadataRepository.getTo() ); | ||||
assertEquals( TEST_REPO, metadataRepository.getRepoId() ); | assertEquals( TEST_REPO, metadataRepository.getRepoId() ); | ||||
assertTrue( | assertTrue( | ||||
feed.getDescription().equals( "New artifacts found in repository 'test-repo' during repository scan." ) ); | feed.getDescription().equals( "New artifacts found in repository 'test-repo' during repository scan." ) ); | ||||
assertTrue( feed.getLanguage().equals( "en-us" ) ); | assertTrue( feed.getLanguage().equals( "en-us" ) ); | ||||
assertTrue( feed.getPublishedDate().equals( whenGathered ) ); | |||||
assertTrue( feed.getPublishedDate().toInstant().equals( whenGathered.toInstant() ) ); | |||||
List<SyndEntry> entries = feed.getEntries(); | List<SyndEntry> entries = feed.getEntries(); | ||||
assertEquals( entries.size(), 1 ); | assertEquals( entries.size(), 1 ); | ||||
assertTrue( | assertTrue( | ||||
entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) ); | |||||
assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) ); | |||||
entries.get( 0 ).getTitle().contains( "New Artifacts in Repository 'test-repo' as of " )); | |||||
assertTrue( entries.get( 0 ).getPublishedDate().toInstant().equals( whenGathered.toInstant() ) ); | |||||
} | } | ||||
private ArtifactMetadata createArtifact( String artifactId, String version, Date whenGathered ) | |||||
private ArtifactMetadata createArtifact( String artifactId, String version, ZonedDateTime whenGathered ) | |||||
{ | { | ||||
ArtifactMetadata artifact = new ArtifactMetadata(); | ArtifactMetadata artifact = new ArtifactMetadata(); | ||||
artifact.setNamespace( "org.apache.archiva" ); | artifact.setNamespace( "org.apache.archiva" ); |
import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||
import java.nio.file.Paths; | import java.nio.file.Paths; | ||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | |||||
import java.time.temporal.TemporalAccessor; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
public void testProcess() | public void testProcess() | ||||
throws Exception | throws Exception | ||||
{ | { | ||||
Date whenGathered = new Date( 123456789 ); | |||||
Date whenGatheredDate = new Date( 123456789 ); | |||||
ZonedDateTime whenGathered = ZonedDateTime.ofInstant(whenGatheredDate.toInstant(), ZoneId.systemDefault()); | |||||
ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" ); | ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" ); | ||||
ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" ); | ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" ); | ||||
Date whenGatheredNext = new Date( 345678912 ); | |||||
Date whenGatheredNextDate = new Date( 345678912 ); | |||||
ZonedDateTime whenGatheredNext = ZonedDateTime.ofInstant(whenGatheredNextDate.toInstant(), ZoneId.systemDefault()); | |||||
ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" ); | ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" ); | ||||
assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.", | assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.", | ||||
feed.getDescription() ); | feed.getDescription() ); | ||||
assertEquals( "en-us", feed.getLanguage() ); | assertEquals( "en-us", feed.getLanguage() ); | ||||
assertEquals( whenGatheredNext, feed.getPublishedDate() ); | |||||
assertEquals( whenGatheredNext.toInstant(), ZonedDateTime.ofInstant(feed.getPublishedDate().toInstant(), ZoneId.systemDefault()).toInstant() ); | |||||
List<SyndEntry> entries = feed.getEntries(); | List<SyndEntry> entries = feed.getEntries(); | ||||
assertEquals( 2, entries.size() ); | assertEquals( 2, entries.size() ); | ||||
assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered, | |||||
entries.get( 0 ).getTitle() ); | |||||
assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() ); | |||||
assertTrue( entries.get(0).getTitle().contains("New Versions of Artifact 'org.apache.archiva:artifact-two' as of ")); | |||||
assertEquals( whenGathered.toInstant(), entries.get( 0 ).getPublishedDate().toInstant() ); | |||||
assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext, | |||||
entries.get( 1 ).getTitle() ); | |||||
assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() ); | |||||
assertTrue(entries.get(1).getTitle().contains("New Versions of Artifact 'org.apache.archiva:artifact-two' as of ")); | |||||
assertEquals( whenGatheredNext.toInstant(), entries.get( 1 ).getPublishedDate().toInstant() ); | |||||
metadataRepositoryControl.verify(); | metadataRepositoryControl.verify(); | ||||
} | } | ||||
private ArtifactMetadata createArtifact( Date whenGathered, String version ) | |||||
private ArtifactMetadata createArtifact(ZonedDateTime whenGathered, String version ) | |||||
{ | { | ||||
ArtifactMetadata artifact = new ArtifactMetadata(); | ArtifactMetadata artifact = new ArtifactMetadata(); | ||||
artifact.setNamespace( GROUP_ID ); | artifact.setNamespace( GROUP_ID ); |
import org.apache.archiva.metadata.repository.AbstractMetadataRepository; | import org.apache.archiva.metadata.repository.AbstractMetadataRepository; | ||||
import org.apache.archiva.metadata.repository.RepositorySession; | import org.apache.archiva.metadata.repository.RepositorySession; | ||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | import java.time.ZonedDateTime; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
public TestMetadataRepository() | public TestMetadataRepository() | ||||
{ | { | ||||
Date whenGathered = new Date( 123456789 ); | |||||
Date whenGatheredDate = new Date( 123456789 ); | |||||
ZonedDateTime whenGathered = ZonedDateTime.ofInstant(whenGatheredDate.toInstant(), ZoneId.systemDefault()); | |||||
addArtifact( "artifact-one", "1.0", whenGathered ); | addArtifact( "artifact-one", "1.0", whenGathered ); | ||||
addArtifact( "artifact-one", "1.1", whenGathered ); | addArtifact( "artifact-one", "1.1", whenGathered ); | ||||
addArtifact( "artifact-four", "1.1-beta-2", whenGathered ); | addArtifact( "artifact-four", "1.1-beta-2", whenGathered ); | ||||
} | } | ||||
private void addArtifact( String projectId, String projectVersion, Date whenGathered ) | |||||
private void addArtifact( String projectId, String projectVersion, ZonedDateTime whenGathered ) | |||||
{ | { | ||||
ArtifactMetadata artifact = new ArtifactMetadata(); | ArtifactMetadata artifact = new ArtifactMetadata(); | ||||
artifact.setFileLastModified( System.currentTimeMillis() ); | artifact.setFileLastModified( System.currentTimeMillis() ); |
*/ | */ | ||||
import javax.xml.bind.annotation.XmlRootElement; | import javax.xml.bind.annotation.XmlRootElement; | ||||
import java.time.ZonedDateTime; | |||||
import java.util.Date; | import java.util.Date; | ||||
/** | /** | ||||
/** | /** | ||||
* When the artifact was found in the repository storage and added to the metadata content repository. | * When the artifact was found in the repository storage and added to the metadata content repository. | ||||
*/ | */ | ||||
private Date whenGathered; | |||||
private ZonedDateTime whenGathered; | |||||
public String getId() | public String getId() | ||||
{ | { | ||||
this.fileLastModified = new Date( fileLastModified ); | this.fileLastModified = new Date( fileLastModified ); | ||||
} | } | ||||
public void setWhenGathered( Date whenGathered ) | |||||
public void setWhenGathered( ZonedDateTime whenGathered ) | |||||
{ | { | ||||
this.whenGathered = whenGathered; | this.whenGathered = whenGathered; | ||||
} | } | ||||
this.sha1 = sha1; | this.sha1 = sha1; | ||||
} | } | ||||
public Date getWhenGathered() | |||||
public ZonedDateTime getWhenGathered() | |||||
{ | { | ||||
return whenGathered; | return whenGathered; | ||||
} | } | ||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
if ( whenGathered != null ? !whenGathered.equals( that.whenGathered ) : that.whenGathered != null ) | |||||
if ( whenGathered != null ? !whenGathered.toInstant().equals( that.whenGathered.toInstant() ) : that.whenGathered != null ) | |||||
{ | { | ||||
return false; | return false; | ||||
} | } |
import org.springframework.test.context.ContextConfiguration; | import org.springframework.test.context.ContextConfiguration; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | import java.time.ZonedDateTime; | ||||
import java.time.temporal.TemporalUnit; | import java.time.temporal.TemporalUnit; | ||||
import java.util.*; | import java.util.*; | ||||
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | ||||
session.save( ); | session.save( ); | ||||
ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).minusSeconds(10); | |||||
ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10); | |||||
tryAssert( ( ) -> { | tryAssert( ( ) -> { | ||||
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null ); | List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null ); | ||||
ArtifactMetadata artifact = createArtifact( ); | ArtifactMetadata artifact = createArtifact( ); | ||||
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | ||||
ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).plusSeconds(10); | |||||
ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10); | |||||
tryAssert( ( ) -> { | tryAssert( ( ) -> { | ||||
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null ); | List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null ); | ||||
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | ||||
session.save( ); | session.save( ); | ||||
ZonedDateTime lower = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).minusSeconds(10); | |||||
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).plusSeconds(10); | |||||
ZonedDateTime lower = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10); | |||||
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10); | |||||
tryAssert( ( ) -> { | tryAssert( ( ) -> { | ||||
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper ); | List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper ); | ||||
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | ||||
session.save( ); | session.save( ); | ||||
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).plusSeconds(10); | |||||
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10); | |||||
tryAssert( ( ) -> { | tryAssert( ( ) -> { | ||||
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper ); | List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper ); | ||||
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); | ||||
session.save( ); | session.save( ); | ||||
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).minusSeconds(10); | |||||
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10); | |||||
tryAssert( ( ) -> { | tryAssert( ( ) -> { | ||||
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper ); | List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper ); | ||||
{ | { | ||||
ArtifactMetadata artifact = new ArtifactMetadata( ); | ArtifactMetadata artifact = new ArtifactMetadata( ); | ||||
artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type ); | artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type ); | ||||
artifact.setWhenGathered( new Date( ) ); | |||||
artifact.setWhenGathered( ZonedDateTime.now() ); | |||||
artifact.setNamespace( TEST_NAMESPACE ); | artifact.setNamespace( TEST_NAMESPACE ); | ||||
artifact.setProject( TEST_PROJECT ); | artifact.setProject( TEST_PROJECT ); | ||||
artifact.setRepositoryId( TEST_REPO_ID ); | artifact.setRepositoryId( TEST_REPO_ID ); |
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import java.time.Instant; | |||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | import java.time.ZonedDateTime; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
// updater | // updater | ||||
ColumnFamilyUpdater<String, String> updater = this.artifactMetadataTemplate.createUpdater( key ); | ColumnFamilyUpdater<String, String> updater = this.artifactMetadataTemplate.createUpdater( key ); | ||||
updater.setLong( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime() ); | updater.setLong( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime() ); | ||||
updater.setLong( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime() ); | |||||
updater.setLong( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().toInstant().toEpochMilli() ); | |||||
updater.setLong( SIZE.toString(), artifactMeta.getSize() ); | updater.setLong( SIZE.toString(), artifactMeta.getSize() ); | ||||
addUpdateStringValue( updater, MD5.toString(), artifactMeta.getMd5() ); | addUpdateStringValue( updater, MD5.toString(), artifactMeta.getMd5() ); | ||||
addUpdateStringValue( updater, SHA1.toString(), artifactMeta.getSha1() ); | addUpdateStringValue( updater, SHA1.toString(), artifactMeta.getSha1() ); | ||||
.addInsertion( key, cf, column( SIZE.toString(), artifactMeta.getSize() ) ) // | .addInsertion( key, cf, column( SIZE.toString(), artifactMeta.getSize() ) ) // | ||||
.addInsertion( key, cf, column( MD5.toString(), artifactMeta.getMd5() ) ) // | .addInsertion( key, cf, column( MD5.toString(), artifactMeta.getMd5() ) ) // | ||||
.addInsertion( key, cf, column( SHA1.toString(), artifactMeta.getSha1() ) ) // | .addInsertion( key, cf, column( SHA1.toString(), artifactMeta.getSha1() ) ) // | ||||
.addInsertion( key, cf, column( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime() ) )// | |||||
.addInsertion( key, cf, column( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().toInstant().toEpochMilli() ) )// | |||||
.execute(); | .execute(); | ||||
} | } | ||||
Long whenGathered = getLongValue( columnSlice, WHEN_GATHERED.toString() ); | Long whenGathered = getLongValue( columnSlice, WHEN_GATHERED.toString() ); | ||||
if ( whenGathered != null ) | if ( whenGathered != null ) | ||||
{ | { | ||||
artifactMetadata.setWhenGathered( new Date( whenGathered ) ); | |||||
artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), ZoneId.of("GMT"))); | |||||
} | } | ||||
return artifactMetadata; | return artifactMetadata; | ||||
} | } | ||||
Long whenGathered = getAsLongValue( columnSlice, WHEN_GATHERED.toString() ); | Long whenGathered = getAsLongValue( columnSlice, WHEN_GATHERED.toString() ); | ||||
if ( whenGathered != null ) | if ( whenGathered != null ) | ||||
{ | { | ||||
artifactMetadata.setWhenGathered( new Date( whenGathered ) ); | |||||
artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), ZoneId.of("GMT"))); | |||||
} | } | ||||
return artifactMetadata; | return artifactMetadata; | ||||
} | } |
import java.nio.file.NoSuchFileException; | import java.nio.file.NoSuchFileException; | ||||
import java.nio.file.Path; | import java.nio.file.Path; | ||||
import java.nio.file.Paths; | import java.nio.file.Paths; | ||||
import java.time.Instant; | |||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | import java.time.ZonedDateTime; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
{ | { | ||||
for ( ArtifactMetadata artifact : getArtifacts( session, repoId, ns, project, version ) ) | for ( ArtifactMetadata artifact : getArtifacts( session, repoId, ns, project, version ) ) | ||||
{ | { | ||||
if ( startTime == null || startTime.isBefore( ZonedDateTime.from(artifact.getWhenGathered().toInstant()) ) ) | |||||
if ( startTime == null || startTime.isBefore( ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())) ) ) | |||||
{ | { | ||||
if ( endTime == null || endTime.isAfter( ZonedDateTime.from(artifact.getWhenGathered().toInstant()) ) ) | |||||
if ( endTime == null || endTime.isAfter( ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())) ) ) | |||||
{ | { | ||||
artifacts.add( artifact ); | artifacts.add( artifact ); | ||||
} | } | ||||
} | } | ||||
else if ( "whenGathered".equals( field ) ) | else if ( "whenGathered".equals( field ) ) | ||||
{ | { | ||||
artifact.setWhenGathered( new Date( Long.parseLong( value ) ) ); | |||||
artifact.setWhenGathered( ZonedDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong( value )), ZoneId.of("GMT") ) ); | |||||
} | } | ||||
else if ( "version".equals( field ) ) | else if ( "version".equals( field ) ) | ||||
{ | { | ||||
properties.setProperty( "artifact:updated:" + id, | properties.setProperty( "artifact:updated:" + id, | ||||
Long.toString( artifact.getFileLastModified().getTime() ) ); | Long.toString( artifact.getFileLastModified().getTime() ) ); | ||||
properties.setProperty( "artifact:whenGathered:" + id, | properties.setProperty( "artifact:whenGathered:" + id, | ||||
Long.toString( artifact.getWhenGathered().getTime() ) ); | |||||
Long.toString( artifact.getWhenGathered().toInstant().toEpochMilli()) ); | |||||
properties.setProperty( "artifact:size:" + id, Long.toString( artifact.getSize() ) ); | properties.setProperty( "artifact:size:" + id, Long.toString( artifact.getSize() ) ); | ||||
if ( artifact.getMd5() != null ) | if ( artifact.getMd5() != null ) | ||||
{ | { |
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||
import java.io.Reader; | import java.io.Reader; | ||||
import java.time.ZoneId; | |||||
import java.time.ZonedDateTime; | import java.time.ZonedDateTime; | ||||
import java.util.*; | import java.util.*; | ||||
import java.util.Map.Entry; | import java.util.Map.Entry; | ||||
cal.setTime( artifactMeta.getFileLastModified() ); | cal.setTime( artifactMeta.getFileLastModified() ); | ||||
node.setProperty( JCR_LAST_MODIFIED, cal ); | node.setProperty( JCR_LAST_MODIFIED, cal ); | ||||
cal = Calendar.getInstance(); | |||||
cal.setTime( artifactMeta.getWhenGathered() ); | |||||
cal = GregorianCalendar.from(artifactMeta.getWhenGathered()); | |||||
node.setProperty( "whenGathered", cal ); | node.setProperty( "whenGathered", cal ); | ||||
node.setProperty( "size", artifactMeta.getSize() ); | node.setProperty( "size", artifactMeta.getSize() ); | ||||
if ( artifactNode.hasProperty( "whenGathered" ) ) | if ( artifactNode.hasProperty( "whenGathered" ) ) | ||||
{ | { | ||||
artifact.setWhenGathered( artifactNode.getProperty( "whenGathered" ).getDate().getTime() ); | |||||
Calendar cal = artifactNode.getProperty("whenGathered").getDate(); | |||||
artifact.setWhenGathered( ZonedDateTime.ofInstant(cal.toInstant(), cal.getTimeZone().toZoneId())); | |||||
} | } | ||||
if ( artifactNode.hasProperty( "size" ) ) | if ( artifactNode.hasProperty( "size" ) ) |