Search in sources :

Example 1 with PreferencesController

use of org.jbei.ice.lib.account.PreferencesController in project ice by JBEI.

the class UserResource method getUserPreferences.

/**
     * @return preferences for a user
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/preferences")
public UserPreferences getUserPreferences(@PathParam("id") long userId) {
    String userIdString = getUserId();
    PreferencesController preferencesController = new PreferencesController();
    return preferencesController.getUserPreferences(userIdString, userId);
}
Also used : PreferencesController(org.jbei.ice.lib.account.PreferencesController)

Example 2 with PreferencesController

use of org.jbei.ice.lib.account.PreferencesController in project ice by JBEI.

the class PartDefaults method get.

/**
     * Retrieves and sets the default values for the entry. Some of these values (e.g. PI, and Funding Source)
     * are set by individual users as part of their personal preferences
     *
     * @param type entry type
     * @return PartData object with the retrieve part defaults
     */
public PartData get(EntryType type) {
    PartData partData = new PartData(type);
    PreferencesController preferencesController = new PreferencesController();
    // pi defaults
    String value = preferencesController.getPreferenceValue(userId, PreferenceKey.PRINCIPAL_INVESTIGATOR.name());
    if (value != null) {
        Account piAccount = this.accountDAO.getByEmail(value);
        if (piAccount == null) {
            partData.setPrincipalInvestigator(value);
        } else {
            partData.setPrincipalInvestigator(piAccount.getFullName());
            partData.setPrincipalInvestigatorEmail(piAccount.getEmail());
            partData.setPrincipalInvestigatorId(piAccount.getId());
        }
    }
    // funding source defaults
    value = preferencesController.getPreferenceValue(userId, PreferenceKey.FUNDING_SOURCE.name());
    if (value != null) {
        partData.setFundingSource(value);
    }
    // owner and creator details
    Account account = this.accountDAO.getByEmail(userId);
    if (account != null) {
        partData.setOwner(account.getFullName());
        partData.setOwnerEmail(account.getEmail());
        partData.setCreator(partData.getOwner());
        partData.setCreatorEmail(partData.getOwnerEmail());
    }
    // set the entry type defaults
    return EntryUtil.setPartDefaults(partData);
}
Also used : Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData) PreferencesController(org.jbei.ice.lib.account.PreferencesController)

Example 3 with PreferencesController

use of org.jbei.ice.lib.account.PreferencesController in project ice by JBEI.

the class UserResource method updatePreference.

/**
     * @return updated preferences for a user
     */
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/preferences/{key}")
public PreferenceInfo updatePreference(@PathParam("id") long userId, @PathParam("key") String key, @QueryParam("value") String value) {
    String userIdString = getUserId();
    PreferencesController preferencesController = new PreferencesController();
    return preferencesController.updatePreference(userIdString, userId, key, value);
}
Also used : PreferencesController(org.jbei.ice.lib.account.PreferencesController)

Aggregations

PreferencesController (org.jbei.ice.lib.account.PreferencesController)3 PartData (org.jbei.ice.lib.dto.entry.PartData)1 Account (org.jbei.ice.storage.model.Account)1