use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DatasetVersionServiceBean method getContributorsNames.
public String getContributorsNames(DatasetVersion version) {
String contNames = "";
for (String id : version.getVersionContributorIdentifiers()) {
id = id.startsWith("@") ? id.substring(1) : id;
AuthenticatedUser au = authService.getAuthenticatedUser(id);
if (au != null) {
if (contNames.isEmpty()) {
contNames = au.getName();
} else {
contNames = contNames + ", " + au.getName();
}
}
}
return contNames;
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DataFileServiceBean method findFileMetadataOptimizedExperimental.
public void findFileMetadataOptimizedExperimental(Dataset owner, DatasetVersion requestedVersion) {
List<DataFile> dataFiles = new ArrayList<>();
List<DataTable> dataTables = new ArrayList<>();
// List<FileMetadata> retList = new ArrayList<>();
// TODO:
// replace these maps with simple lists and run binary search on them. -- 4.2.1
Map<Long, AuthenticatedUser> userMap = new HashMap<>();
Map<Long, Integer> filesMap = new HashMap<>();
Map<Long, Integer> datatableMap = new HashMap<>();
Map<Long, Integer> categoryMap = new HashMap<>();
Map<Long, Set<Integer>> fileTagMap = new HashMap<>();
List<String> fileTagLabels = DataFileTag.listTags();
int i = 0;
List<Object[]> dataTableResults = em.createNativeQuery("SELECT t0.ID, t0.DATAFILE_ID, t0.UNF, t0.CASEQUANTITY, t0.VARQUANTITY, t0.ORIGINALFILEFORMAT FROM dataTable t0, dataFile t1, dvObject t2 WHERE ((t0.DATAFILE_ID = t1.ID) AND (t1.ID = t2.ID) AND (t2.OWNER_ID = " + owner.getId() + ")) ORDER BY t0.ID").getResultList();
for (Object[] result : dataTableResults) {
DataTable dataTable = new DataTable();
long fileId = ((Number) result[1]).longValue();
dataTable.setId(((Number) result[1]).longValue());
dataTable.setUnf((String) result[2]);
dataTable.setCaseQuantity((Long) result[3]);
dataTable.setVarQuantity((Long) result[4]);
dataTable.setOriginalFileFormat((String) result[5]);
dataTables.add(dataTable);
datatableMap.put(fileId, i++);
}
logger.fine("Retrieved " + dataTables.size() + " DataTable objects.");
i = 0;
List<Object[]> dataTagsResults = em.createNativeQuery("SELECT t0.DATAFILE_ID, t0.TYPE FROM DataFileTag t0, dvObject t1 WHERE (t1.ID = t0.DATAFILE_ID) AND (t1.OWNER_ID=" + owner.getId() + ")").getResultList();
for (Object[] result : dataTagsResults) {
Long datafile_id = (Long) result[0];
Integer tagtype_id = (Integer) result[1];
if (fileTagMap.get(datafile_id) == null) {
fileTagMap.put(datafile_id, new HashSet<>());
}
fileTagMap.get(datafile_id).add(tagtype_id);
i++;
}
dataTagsResults = null;
logger.fine("Retrieved " + i + " data tags.");
i = 0;
List<Object[]> fileResults = em.createNativeQuery("SELECT t0.ID, t0.CREATEDATE, t0.INDEXTIME, t0.MODIFICATIONTIME, t0.PERMISSIONINDEXTIME, t0.PERMISSIONMODIFICATIONTIME, t0.PUBLICATIONDATE, t0.CREATOR_ID, t0.RELEASEUSER_ID, t1.CONTENTTYPE, t0.STORAGEIDENTIFIER, t1.FILESIZE, t1.INGESTSTATUS, t1.CHECKSUMVALUE, t1.RESTRICTED, t1.CHECKSUMTYPE, t1.PREVIOUSDATAFILEID, t1.ROOTDATAFILEID FROM DVOBJECT t0, DATAFILE t1 WHERE ((t0.OWNER_ID = " + owner.getId() + ") AND ((t1.ID = t0.ID) AND (t0.DTYPE = 'DataFile'))) ORDER BY t0.ID").getResultList();
for (Object[] result : fileResults) {
Integer file_id = (Integer) result[0];
DataFile dataFile = new DataFile();
dataFile.setMergeable(false);
dataFile.setId(file_id.longValue());
Timestamp createDate = (Timestamp) result[1];
Timestamp indexTime = (Timestamp) result[2];
Timestamp modificationTime = (Timestamp) result[3];
Timestamp permissionIndexTime = (Timestamp) result[4];
Timestamp permissionModificationTime = (Timestamp) result[5];
Timestamp publicationDate = (Timestamp) result[6];
dataFile.setCreateDate(createDate);
dataFile.setIndexTime(indexTime);
dataFile.setModificationTime(modificationTime);
dataFile.setPermissionIndexTime(permissionIndexTime);
dataFile.setPermissionModificationTime(permissionModificationTime);
dataFile.setPublicationDate(publicationDate);
Long creatorId = (Long) result[7];
if (creatorId != null) {
AuthenticatedUser creator = userMap.get(creatorId);
if (creator == null) {
creator = userService.find(creatorId);
if (creator != null) {
userMap.put(creatorId, creator);
}
}
if (creator != null) {
dataFile.setCreator(creator);
}
}
dataFile.setOwner(owner);
Long releaseUserId = (Long) result[8];
if (releaseUserId != null) {
AuthenticatedUser releaseUser = userMap.get(releaseUserId);
if (releaseUser == null) {
releaseUser = userService.find(releaseUserId);
if (releaseUser != null) {
userMap.put(releaseUserId, releaseUser);
}
}
if (releaseUser != null) {
dataFile.setReleaseUser(releaseUser);
}
}
String contentType = (String) result[9];
if (contentType != null) {
dataFile.setContentType(contentType);
}
String storageIdentifier = (String) result[10];
if (storageIdentifier != null) {
dataFile.setStorageIdentifier(storageIdentifier);
}
Long fileSize = (Long) result[11];
if (fileSize != null) {
dataFile.setFilesize(fileSize);
}
if (result[12] != null) {
String ingestStatusString = (String) result[12];
dataFile.setIngestStatus(ingestStatusString.charAt(0));
}
String md5 = (String) result[13];
if (md5 != null) {
dataFile.setChecksumValue(md5);
}
Boolean restricted = (Boolean) result[14];
if (restricted != null) {
dataFile.setRestricted(restricted);
}
String checksumType = (String) result[15];
if (checksumType != null) {
try {
// In the database we store "SHA1" rather than "SHA-1".
DataFile.ChecksumType typeFromStringInDatabase = DataFile.ChecksumType.valueOf(checksumType);
dataFile.setChecksumType(typeFromStringInDatabase);
} catch (IllegalArgumentException ex) {
logger.info("Exception trying to convert " + checksumType + " to enum: " + ex);
}
}
Long previousDataFileId = (Long) result[16];
if (previousDataFileId != null) {
dataFile.setPreviousDataFileId(previousDataFileId);
}
Long rootDataFileId = (Long) result[17];
if (rootDataFileId != null) {
dataFile.setRootDataFileId(rootDataFileId);
}
if (datatableMap.get(dataFile.getId()) != null) {
dataTables.get(datatableMap.get(dataFile.getId())).setDataFile(dataFile);
dataFile.setDataTable(dataTables.get(datatableMap.get(dataFile.getId())));
}
if (fileTagMap.get(dataFile.getId()) != null) {
for (Integer tag_id : fileTagMap.get(dataFile.getId())) {
DataFileTag tag = new DataFileTag();
tag.setTypeByLabel(fileTagLabels.get(tag_id));
tag.setDataFile(dataFile);
dataFile.addTag(tag);
}
}
dataFile.setFileAccessRequesters(retrieveFileAccessRequesters(dataFile));
dataFiles.add(dataFile);
filesMap.put(dataFile.getId(), i++);
}
fileResults = null;
logger.fine("Retrieved and cached " + i + " datafiles.");
i = 0;
for (DataFileCategory fileCategory : owner.getCategories()) {
// logger.fine("category: id="+fileCategory.getId());
categoryMap.put(fileCategory.getId(), i++);
}
logger.fine("Retrieved " + i + " file categories attached to the dataset.");
if (requestedVersion != null) {
requestedVersion.setFileMetadatas(retrieveFileMetadataForVersion(owner, requestedVersion, dataFiles, filesMap, categoryMap));
} else {
for (DatasetVersion version : owner.getVersions()) {
version.setFileMetadatas(retrieveFileMetadataForVersion(owner, version, dataFiles, filesMap, categoryMap));
logger.fine("Retrieved " + version.getFileMetadatas().size() + " filemetadatas for the version " + version.getId());
}
}
owner.setFiles(dataFiles);
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class ApiTokenPage method getApiToken.
public String getApiToken() {
if (session.getUser().isAuthenticated()) {
AuthenticatedUser au = (AuthenticatedUser) session.getUser();
apiToken = authSvc.findApiTokenByUser(au);
if (apiToken != null) {
return apiToken.getTokenString();
} else {
List<String> arguments = new ArrayList<>();
arguments.add(au.getName());
return BundleUtil.getStringFromBundle("apitoken.notFound", arguments);
}
} else {
// It should be impossible to get here from the UI.
return "Only authenticated users can have API tokens.";
}
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class ApiTokenPage method checkForApiToken.
public boolean checkForApiToken() {
if (session.getUser().isAuthenticated()) {
AuthenticatedUser au = (AuthenticatedUser) session.getUser();
apiToken = authSvc.findApiTokenByUser(au);
if (apiToken != null) {
return true;
}
}
return false;
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class ApiTokenPage method generate.
public void generate() {
if (session.getUser().isAuthenticated()) {
AuthenticatedUser au = (AuthenticatedUser) session.getUser();
apiToken = authSvc.findApiTokenByUser(au);
if (apiToken != null) {
authSvc.removeApiToken(au);
}
/**
* @todo DRY! Stolen from BuiltinUsers API page
*/
ApiToken newToken = new ApiToken();
newToken.setTokenString(java.util.UUID.randomUUID().toString());
newToken.setAuthenticatedUser(au);
Calendar c = Calendar.getInstance();
newToken.setCreateTime(new Timestamp(c.getTimeInMillis()));
c.roll(Calendar.YEAR, 1);
newToken.setExpireTime(new Timestamp(c.getTimeInMillis()));
authSvc.save(newToken);
}
}
Aggregations