mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-15 15:02:20 +00:00
Reverse merged HEAD (5.1)
122540 adragoi: Merged DEV to HEAD (5.1) 122252 ACE-5093 : Allow file content URLs to be generated by a provider - implemented TimeBasedFileContentUrlProvider,VolumeAwareFileContentUrlProvider and test classes 121979 ACE-5093 : Allow file content URLs to be generated by a provider - added deprecated annotation git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@122918 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,8 +21,10 @@ package org.alfresco.repo.content.filestore;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
@@ -37,6 +39,7 @@ import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.util.Deleter;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -82,7 +85,6 @@ public class FileContentStore
|
||||
private boolean readOnly;
|
||||
private ApplicationContext applicationContext;
|
||||
private boolean deleteEmptyDirs = true;
|
||||
private FileContentUrlProvider fileContentUrlProvider = new TimeBasedFileContentUrlProvider();
|
||||
|
||||
/**
|
||||
* Private: for Spring-constructed instances only.
|
||||
@@ -199,10 +201,6 @@ public class FileContentStore
|
||||
{
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public void setFileContentUrlProvider(FileContentUrlProvider fileContentUrlProvider) {
|
||||
this.fileContentUrlProvider = fileContentUrlProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new URL and file appropriate to it.
|
||||
@@ -212,7 +210,7 @@ public class FileContentStore
|
||||
*/
|
||||
/*package*/ File createNewFile() throws IOException
|
||||
{
|
||||
String contentUrl = fileContentUrlProvider.createNewFileStoreUrl();
|
||||
String contentUrl = FileContentStore.createNewFileStoreUrl();
|
||||
return createNewFile(contentUrl);
|
||||
}
|
||||
|
||||
@@ -648,13 +646,28 @@ public class FileContentStore
|
||||
* stores that are compatible with Alfresco.
|
||||
*
|
||||
* @return Returns a new and unique content URL
|
||||
*
|
||||
* @deprecated New file store URLs are now generated using {@link FileContentUrlProvider}.
|
||||
* In org.alfresco.repo.content.filestore package use {@link TimeBasedFileContentUrlProvider}
|
||||
*/
|
||||
public static String createNewFileStoreUrl()
|
||||
{
|
||||
return TimeBasedFileContentUrlProvider.createNewFileStoreUrl(0);
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
int month = calendar.get(Calendar.MONTH) + 1; // 0-based
|
||||
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = calendar.get(Calendar.MINUTE);
|
||||
// create the URL
|
||||
StringBuilder sb = new StringBuilder(20);
|
||||
sb.append(FileContentStore.STORE_PROTOCOL)
|
||||
.append(ContentStore.PROTOCOL_DELIMITER)
|
||||
.append(year).append('/')
|
||||
.append(month).append('/')
|
||||
.append(day).append('/')
|
||||
.append(hour).append('/')
|
||||
.append(minute).append('/')
|
||||
.append(GUID.generate()).append(".bin");
|
||||
String newContentUrl = sb.toString();
|
||||
// done
|
||||
return newContentUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2016 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.content.filestore;
|
||||
|
||||
/**
|
||||
* Provider API for file content store URL implementations
|
||||
* @author Andreea Dragoi
|
||||
* @since 5.1
|
||||
*/
|
||||
interface FileContentUrlProvider
|
||||
{
|
||||
/**
|
||||
* Content URLs must consist of a prefix or protocol followed by an implementation-specific identifier
|
||||
* @return file content store URL
|
||||
*/
|
||||
public String createNewFileStoreUrl();
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2016 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.content.filestore;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Default Content URL provider for file stores.
|
||||
* Content URL format is <b>store://year/month/day/hour/minute/GUID.bin</b>,
|
||||
* but can be configured to include provision for splitting data into
|
||||
* buckets within <b>minute</b> range through minuteBucketCount property :
|
||||
* <b>store://year/month/day/hour/minute/bucket/GUID.bin</b> <br>
|
||||
* <ul>
|
||||
* <li> <b>store://</b>: prefix identifying an Alfresco content stores
|
||||
* regardless of the persistence mechanism. </li>
|
||||
* <li> <b>year</b>: year </li>
|
||||
* <li> <b>month</b>: 1-based month of the year </li>
|
||||
* <li> <b>day</b>: 1-based day of the month </li>
|
||||
* <li> <b>hour</b>: 0-based hour of the day </li>
|
||||
* <li> <b>minute</b>: 0-based minute of the hour </li>
|
||||
* <li> <b>bucket</b>: 0-based bucket depending second of minute </li>
|
||||
* <li> <b>GUID</b>: A unique identifier </li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* @author Andreea Dragoi
|
||||
* @since 5.1
|
||||
*/
|
||||
|
||||
class TimeBasedFileContentUrlProvider implements FileContentUrlProvider
|
||||
{
|
||||
protected int minuteBucketCount = 0;
|
||||
|
||||
public void setMinuteBucketCount(int minuteBucketCount)
|
||||
{
|
||||
this.minuteBucketCount = minuteBucketCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createNewFileStoreUrl()
|
||||
{
|
||||
return createNewFileStoreUrl(minuteBucketCount);
|
||||
}
|
||||
|
||||
public static String createTimeBasedPath(int minuteBucketCount){
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
int month = calendar.get(Calendar.MONTH) + 1; // 0-based
|
||||
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = calendar.get(Calendar.MINUTE);
|
||||
// create the URL
|
||||
StringBuilder sb = new StringBuilder(20);
|
||||
sb.append(year).append('/')
|
||||
.append(month).append('/')
|
||||
.append(day).append('/')
|
||||
.append(hour).append('/')
|
||||
.append(minute).append('/');
|
||||
|
||||
if (minuteBucketCount != 0)
|
||||
{
|
||||
long seconds = System.currentTimeMillis() % (60 * 1000);
|
||||
int actualBucket = (int) seconds / ((60 * 1000) / minuteBucketCount);
|
||||
sb.append(actualBucket).append('/');
|
||||
}
|
||||
//done
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String createNewFileStoreUrl(int minuteBucketCount)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(20);
|
||||
sb.append(FileContentStore.STORE_PROTOCOL);
|
||||
sb.append(ContentStore.PROTOCOL_DELIMITER);
|
||||
sb.append(createTimeBasedPath(minuteBucketCount));
|
||||
sb.append(GUID.generate()).append(".bin");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2016 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.content.filestore;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Content URL provider for file stores which allows routing content from a store to a selection of filesystem volumes.
|
||||
* Content is randomly distributed on configured volumes.
|
||||
* Content URL format is <b>store://volume/year/month/day/hour/minute/GUID.bin</b>,
|
||||
* As {@link TimeBasedFileContentUrlProvider TimeBasedFileContentUrlProvider} can be configured to include provision for
|
||||
* splitting data into buckets within <b>minute</b> range
|
||||
* @author Andreea Dragoi
|
||||
* @since 5.1
|
||||
*/
|
||||
class VolumeAwareContentUrlProvider extends TimeBasedFileContentUrlProvider
|
||||
{
|
||||
private String[] volumes;
|
||||
private Random random = new Random();
|
||||
|
||||
/**
|
||||
* @param volumeNames(name of volumes separated by comma)
|
||||
*/
|
||||
public VolumeAwareContentUrlProvider(String volumeNames)
|
||||
{
|
||||
if (volumeNames == null || volumeNames.isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid volumeNames argument");
|
||||
}
|
||||
this.volumes = volumeNames.split(",");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createNewFileStoreUrl()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(20);
|
||||
sb.append(FileContentStore.STORE_PROTOCOL)
|
||||
.append(ContentStore.PROTOCOL_DELIMITER)
|
||||
.append(chooseVolume()).append("/")
|
||||
.append(TimeBasedFileContentUrlProvider.createTimeBasedPath(minuteBucketCount))
|
||||
.append(GUID.generate()).append(".bin");
|
||||
String newContentUrl = sb.toString();
|
||||
return newContentUrl;
|
||||
}
|
||||
|
||||
private String chooseVolume()
|
||||
{
|
||||
int volumesNum = volumes.length;
|
||||
return volumes[random.nextInt(volumesNum)];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user