Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package uws.service.file;
/*
* This file is part of UWSLibrary.
*
* UWSLibrary 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.
*
* UWSLibrary 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 UWSLibrary. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2012 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
*/
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import uws.job.user.JobOwner;
/**
* Let's extracting the group name of any given job owner.
* The name of the extracted name is the first letter of the given owner ID but if none can be found "_" is returned.
*
* @author Gr&ecaute;gory Mantelet (CDS)
* @version 04/2012
*/
public class DefaultOwnerGroupIdentifier implements OwnerGroupIdentifier {
/** Pattern to extract the root directory of a user directory from its ID. */
protected static final Pattern DIR_PREFIX_PATTERN = Pattern.compile(".*([a-zA-Z])[^a-zA-Z]*");
@Override
gmantele
committed
public String getOwnerGroup(JobOwner owner){
if (owner == null || owner.getID() == null || owner.getID().trim().isEmpty())
return null;
else{
// The user directory name = userID in which each directory separator char are replaced by a _ (=> no confusion with a path):
String userDir = owner.getID().trim().replaceAll(File.separator, "_");
// The parent directory = the first LETTER of the userID or _ if none can be found:
String parentDir = "_";
Matcher m = DIR_PREFIX_PATTERN.matcher(userDir);
if (m.matches())
parentDir = m.group(1).toLowerCase();
return parentDir;
}
}
}