Commit 5e12c174 authored by Matija Obreza's avatar Matija Obreza
Browse files

Repository uses RepositoryFile#storagePath (first characters of UUID) as directories

parent 5ce70bc3
/*
* Copyright 2016 Global Crop Diversity Trust, www.croptrust.org
* Copyright 2017 Global Crop Diversity Trust, www.croptrust.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -39,8 +39,8 @@ import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.EntityId;
import org.genesys.blocks.model.InMemoryIdGenerator;
import org.genesys.filerepository.metadata.BaseMetadata;
import org.genesys.filerepository.service.BytesStorageService;
// TODO: Auto-generated Javadoc
/**
* The Class RepositoryFile.
*/
......@@ -157,7 +157,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getIdentifier()
*/
// TODO See if we can have a setter instead of this formula.
......@@ -180,7 +179,7 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
}
/**
* Gets the filename.
* Gets the filename as used by {@link BytesStorageService}.
*
* @return the filename
*/
......@@ -199,6 +198,29 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
return sb.toString();
}
/**
* Get the path of the file used by {@link BytesStorageService}
*
* @return
*/
@Transient
public String getStoragePath() {
if (uuid == null) {
return null;
}
return "/" + uuid.toString().substring(0, 3);
}
/**
* Get the full path to the file as used by {@link BytesStorageService}. This is the concatenation of {@link #getStoragePath()} and {@link #getFilename()}.
*
* @return
*/
@Transient
public String getStorageFullPath() {
return getStoragePath() + "/" + getFilename();
}
@Override
public Long getId() {
return id;
......@@ -228,7 +250,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getTitle()
*/
@Override
......@@ -247,7 +268,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getSubject()
*/
@Override
......@@ -266,7 +286,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getDescription()
*/
@Override
......@@ -285,7 +304,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getCreator()
*/
@Override
......@@ -304,7 +322,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getCreated()
*/
@Override
......@@ -323,7 +340,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getRightsHolder( )
*/
@Override
......@@ -342,7 +358,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getAccessRights( )
*/
@Override
......@@ -361,7 +376,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getLicense()
*/
@Override
......@@ -380,7 +394,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getFormat()
*/
@Override
......@@ -408,7 +421,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getExtent()
*/
@Override
......@@ -427,7 +439,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata# getBibliographicCitation()
*/
@Override
......@@ -446,7 +457,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getDateSubmitted ()
*/
@Override
......@@ -456,7 +466,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see org.genesys.filerepository.metadata.BaseMetadata#getModified()
*/
@Override
......@@ -644,7 +653,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
......@@ -657,7 +665,6 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
......
/*
* Copyright 2016 Global Crop Diversity Trust, www.croptrust.org
* Copyright 2017 Global Crop Diversity Trust, www.croptrust.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -134,7 +134,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
repositoryFile = repositoryFilePersistence.save(repositoryFile);
try {
bytesStorageService.upsert(repositoryFile.getPath(), repositoryFile.getFilename(), bytes);
bytesStorageService.upsert(repositoryFile.getStoragePath(), repositoryFile.getFilename(), bytes);
} catch (final IOException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Failed to upload bytes", e);
......@@ -184,7 +184,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
repositoryImage = repositoryImagePersistence.save(repositoryImage);
try {
bytesStorageService.upsert(repositoryImage.getPath(), repositoryImage.getFilename(), bytes);
bytesStorageService.upsert(repositoryImage.getStoragePath(), repositoryImage.getFilename(), bytes);
} catch (final IOException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Failed to upload bytes", e);
......@@ -248,11 +248,11 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
* @see org.genesys.filerepository.service.RepositoryService#getFileBytes (java.lang.String, java.lang.String)
*/
@Override
public byte[] getFileBytes(final String repositoryPath, final String filename) throws NoSuchRepositoryFileException {
public byte[] getFileBytes(final String storagePath, final String filename) throws NoSuchRepositoryFileException {
byte[] data = null;
try {
data = bytesStorageService.get(repositoryPath, filename);
data = bytesStorageService.get(storagePath, filename);
} catch (final IOException e) {
e.printStackTrace();
}
......@@ -262,7 +262,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
@Override
public byte[] getFileBytes(RepositoryFile repositoryFile) throws IOException {
return bytesStorageService.get(repositoryFile.getPath(), repositoryFile.getFilename());
return bytesStorageService.get(repositoryFile.getStoragePath(), repositoryFile.getFilename());
}
/*
......@@ -347,7 +347,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
LOG.debug("updateByes length={} repoFile.size={}", bytes.length, repositoryFile.getSize());
repositoryFile.setContentType(contentType);
bytesStorageService.upsert(repositoryFile.getPath(), repositoryFile.getFilename(), bytes);
bytesStorageService.upsert(repositoryFile.getStoragePath(), repositoryFile.getFilename(), bytes);
return repositoryFilePersistence.save(repositoryFile);
}
......@@ -374,7 +374,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
fillImageProperties(repositoryImage, bytes);
bytesStorageService.upsert(repositoryImage.getPath(), repositoryImage.getFilename(), bytes);
bytesStorageService.upsert(repositoryImage.getStoragePath(), repositoryImage.getFilename(), bytes);
return repositoryImagePersistence.save(repositoryImage);
}
......@@ -409,7 +409,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
return removeImage((RepositoryImage) repositoryFile);
}
bytesStorageService.remove(repositoryFile.getPath(), repositoryFile.getFilename());
bytesStorageService.remove(repositoryFile.getStoragePath(), repositoryFile.getFilename());
repositoryFilePersistence.delete(repositoryFile);
return repositoryFile;
}
......@@ -421,7 +421,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
throw new NoSuchRepositoryFileException();
}
bytesStorageService.remove(repositoryImage.getPath(), repositoryImage.getFilename());
bytesStorageService.remove(repositoryImage.getStoragePath(), repositoryImage.getFilename());
repositoryImagePersistence.delete(repositoryImage);
return repositoryImage;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment