use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.
the class UserApiKeys method getKeys.
/**
* Retrieves either list of available keys for current user or all keys.
* If requesting all keys then user must be an administrator
*
* @param limit maximum number of keys to retrieve
* @param offset paging parameter start
* @param sortField field to sort on
* @param asc whether the retrieve order is in ascending order
* @param getAvailable whether to retrieve all available keys or restrict by current user
* @return wrapper around list of retrieved keys including number available
* @throws PermissionException if <code>getAvailable</code> is true but user making the request does not have
* administrative privileges
*/
public Results<AccessKey> getKeys(int limit, int offset, String sortField, boolean asc, boolean getAvailable) {
Results<AccessKey> accessKeyResults = new Results<>();
List<ApiKey> results;
AccountController accountController = new AccountController();
boolean isAdmin = accountController.isAdministrator(this.userId);
if (getAvailable) {
if (!isAdmin)
throw new PermissionException("Cannot retrieve all api keys without admin privileges");
results = apiKeyDAO.getAllApiKeys(sortField, limit, offset, asc);
} else {
results = apiKeyDAO.getApiKeysForUser(userId, sortField, limit, offset, asc);
}
for (ApiKey key : results) {
AccessKey accessKey = key.toDataTransferObject();
Account account = accountController.getByEmail(key.getOwnerEmail());
accessKey.setAccount(account.toDataTransferObject());
accessKeyResults.getData().add(accessKey);
}
// get count
String user = getAvailable ? null : this.userId;
long count = apiKeyDAO.getApiKeysCount(user);
accessKeyResults.setResultCount(count);
return accessKeyResults;
}
use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.
the class PartTraceSequences method getTraces.
public Results<TraceSequenceAnalysis> getTraces(int start, int limit) {
entryAuthorization.expectRead(userId, entry);
List<TraceSequence> sequences = dao.getByEntry(entry, start, limit);
Results<TraceSequenceAnalysis> results = new Results<>();
if (sequences == null)
return results;
for (TraceSequence traceSequence : sequences) {
TraceSequenceAnalysis analysis = traceSequence.toDataTransferObject();
AccountTransfer accountTransfer = new AccountTransfer();
String depositor = traceSequence.getDepositor();
boolean canEdit = canEdit(userId, depositor, entry);
analysis.setCanEdit(canEdit);
Account account = DAOFactory.getAccountDAO().getByEmail(traceSequence.getDepositor());
if (account != null) {
accountTransfer.setFirstName(account.getFirstName());
accountTransfer.setLastName(account.getLastName());
accountTransfer.setEmail(account.getEmail());
accountTransfer.setId(account.getId());
}
analysis.setDepositor(accountTransfer);
results.getData().add(analysis);
}
// get count
int count = dao.getCountByEntry(entry);
results.setResultCount(count);
return results;
}
use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.
the class EntryHistory method get.
public Results<History> get(int limit, int offset, boolean asc, String sort) {
entryAuthorization.expectWrite(userId, entry);
List<Audit> list = dao.getAuditsForEntry(entry, limit, offset, asc, sort);
Results<History> results = new Results<>();
AccountDAO accountDAO = DAOFactory.getAccountDAO();
for (Audit audit : list) {
History history = audit.toDataTransferObject();
if (history.getPartner() == null) {
Account account = accountDAO.getByEmail(history.getUserId());
if (account != null)
history.setAccount(account.toDataTransferObject());
}
results.getData().add(history);
}
long count = dao.getAuditsForEntryCount(this.entry);
results.setResultCount(count);
return results;
}
use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.
the class TraceSequences method getTraces.
public Results<TraceSequenceAnalysis> getTraces(int start, int limit) {
entryAuthorization.expectRead(userId, entry);
List<TraceSequence> sequences = dao.getByEntry(entry, start, limit);
Results<TraceSequenceAnalysis> results = new Results<>();
if (sequences == null)
return results;
for (TraceSequence traceSequence : sequences) {
TraceSequenceAnalysis analysis = traceSequence.toDataTransferObject();
AccountTransfer accountTransfer = new AccountTransfer();
String depositor = traceSequence.getDepositor();
boolean canEdit = canEdit(userId, depositor, entry);
analysis.setCanEdit(canEdit);
Account account = DAOFactory.getAccountDAO().getByEmail(traceSequence.getDepositor());
if (account != null) {
accountTransfer.setFirstName(account.getFirstName());
accountTransfer.setLastName(account.getLastName());
accountTransfer.setEmail(account.getEmail());
accountTransfer.setId(account.getId());
}
analysis.setDepositor(accountTransfer);
results.getData().add(analysis);
}
// get count
int count = dao.getCountByEntry(entry);
results.setResultCount(count);
return results;
}
use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.
the class CollectionEntries method getPersonalEntries.
/**
* Retrieves entries owned by user
*
* @param field sort field
* @param asc sort order
* @param offset paging start
* @param limit maximum number of entries to retrieve
* @param filter optional text to filter entries by
* @return wrapper around list of parts that conform to the parameters and the maximum number
* of such entries that are available
* @throws PermissionException on null user id which is required for owner entries
*/
protected Results<PartData> getPersonalEntries(ColumnField field, boolean asc, int offset, int limit, String filter) {
if (userId == null || userId.isEmpty())
throw new PermissionException("User id is required to retrieve owner entries");
OwnerEntries ownerEntries = new OwnerEntries(userId, userId);
final List<PartData> entries = ownerEntries.retrieveOwnerEntries(field, asc, offset, limit, filter);
final long count = ownerEntries.getNumberOfOwnerEntries();
Results<PartData> results = new Results<>();
results.setResultCount(count);
results.setData(entries);
return results;
}
Aggregations