use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupDAO method getByIdList.
public List<Group> getByIdList(Set<Long> idsSet) {
try {
CriteriaQuery<Group> query = getBuilder().createQuery(Group.class);
Root<Group> from = query.from(Group.class);
query.where(from.get("id").in(idsSet));
return currentSession().createQuery(query).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class MessageDAO method retrieveNewMessageCount.
public int retrieveNewMessageCount(Account account) {
try {
StringBuilder builder = new StringBuilder();
builder.append("select count(id) from message m where m.is_read=false AND (m.id in ").append("(select message_id from message_destination_accounts where account_id = ").append(account.getId()).append(")");
if (!account.getGroups().isEmpty()) {
builder.append(" OR m.id in (select message_id from message_destination_groups where group_id in (");
int i = 0;
for (Group group : account.getGroups()) {
if (i > 0)
builder.append(", ");
builder.append(group.getId());
i += 1;
}
builder.append("))");
}
builder.append(")");
NativeQuery query = currentSession().createNativeQuery(builder.toString());
Number number = (Number) query.uniqueResult();
return number.intValue();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class AccountController method authenticate.
/**
* Authenticate a user in the database.
* <p>
* Using the {@link org.jbei.ice.lib.account.authentication.IAuthentication} specified in the
* settings file, authenticate the user, and return the sessionData
*
* @param login
* @param password
* @param ip IP Address of the user.
* @return the account identifier (email) on a successful login, otherwise {@code null}
*/
protected Account authenticate(final String login, final String password, final String ip) {
final IAuthentication authentication = new LocalAuthentication();
String email;
try {
email = authentication.authenticates(login.trim(), password);
if (email == null) {
loginFailureCooldown();
return null;
}
} catch (final AuthenticationException e2) {
loginFailureCooldown();
return null;
}
Account account = dao.getByEmail(email);
if (account == null)
return null;
AccountPreferences accountPreferences = accountPreferencesDAO.getAccountPreferences(account);
if (accountPreferences == null) {
accountPreferences = new AccountPreferences();
accountPreferences.setAccount(account);
accountPreferencesDAO.create(accountPreferences);
}
// add to public groups
List<Group> groups = groupDAO.getGroupsBy(GroupType.PUBLIC, true);
try {
if (groups != null) {
for (Group group : groups) {
if (!account.getGroups().contains(group)) {
account.getGroups().add(group);
}
}
dao.update(account);
}
} catch (Exception e) {
Logger.error(e);
}
account.setIp(ip);
account.setLastLoginTime(Calendar.getInstance().getTime());
account = save(account);
UserSessions.createNewSessionForUser(account.getEmail());
return account;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class EntriesAsCSV method writeList.
/**
* Iterate through list of entries and extract values
*
* @param userId identifier of user making request
* @throws IOException on Exception write values to file
*/
private void writeList(String userId, EntryField... fields) throws IOException {
// filter entries based on what the user is allowed to see if the user is not an admin
Account account = this.accountDAO.getByEmail(userId);
if (account.getType() != AccountType.ADMIN) {
List<Group> accountGroups = new GroupController().getAllGroups(account);
entries = permissionDAO.getCanReadEntries(account, accountGroups, entries);
}
if (entries == null) {
Logger.warn("No entries to convert to csv format");
return;
}
// write headers
Path tmpPath = Paths.get(Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY));
File tmpFile = File.createTempFile("ice-", ".csv", tmpPath.toFile());
csvPath = tmpFile.toPath();
FileWriter fileWriter = new FileWriter(tmpFile);
if (fields == null || fields.length == 0)
fields = getEntryFields();
String[] headers = getCSVHeaders(fields);
Set<Long> sequenceSet = new HashSet<>();
try (CSVWriter writer = new CSVWriter(fileWriter)) {
writer.writeNext(headers);
// write entry fields
for (long entryId : entries) {
Entry entry = dao.get(entryId);
// get contents and write data out
String[] line = new String[fields.length + 3];
line[0] = entry.getCreationTime().toString();
line[1] = entry.getPartNumber();
int i = 1;
for (EntryField field : fields) {
line[i + 1] = EntryUtil.entryFieldToValue(entry, field);
i += 1;
}
if (this.includeSequences && sequenceDAO.hasSequence(entryId)) {
line[i + 1] = getSequenceName(entry);
sequenceSet.add(entryId);
} else {
line[i + 1] = "";
}
writer.writeNext(line);
}
}
writeZip(userId, sequenceSet);
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class Entries method getCollectionEntries.
protected List<Long> getCollectionEntries(String collection, boolean all, EntryType type) {
if (collection == null || collection.isEmpty())
return null;
Account account = accountDAO.getByEmail(userId);
List<Long> entries;
switch(collection.toLowerCase()) {
case "personal":
if (all)
type = null;
entries = dao.getOwnerEntryIds(userId, type);
break;
case "shared":
entries = dao.sharedWithUserEntryIds(account, account.getGroups());
break;
case "available":
Group publicGroup = new GroupController().createOrRetrievePublicGroup();
entries = dao.getVisibleEntryIds(account.getType() == AccountType.ADMIN, publicGroup);
break;
default:
return null;
}
return entries;
}
Aggregations