Search in sources :

Example 1 with ExpandoColumn

use of com.liferay.portlet.expando.model.ExpandoColumn in project liferay-ide by liferay.

the class LiferayAppDataService method doGetPersonData.

protected DataCollection doGetPersonData(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, SecurityToken securityToken) throws Exception {
    long companyId = getCompanyId(securityToken);
    Map<String, Map<String, String>> peopleAppData = new HashMap<String, Map<String, String>>();
    List<ExpandoColumn> expandoColumns = getExpandoColumns(companyId, appId);
    if (expandoColumns == null) {
        return null;
    }
    if (fields.isEmpty()) {
        fields = new LinkedHashSet<String>();
        for (ExpandoColumn expandoColumn : expandoColumns) {
            fields.add(expandoColumn.getName());
        }
    }
    for (UserId userId : userIds) {
        String userIdString = userId.getUserId(securityToken);
        long userIdLong = GetterUtil.getLong(userIdString);
        Map<String, String> personAppData = new HashMap<String, String>();
        for (String field : fields) {
            String value = getExpandoValue(companyId, appId, userIdLong, getColumnName(appId, field));
            personAppData.put(field, value);
        }
        peopleAppData.put(userIdString, personAppData);
    }
    return new DataCollection(peopleAppData);
}
Also used : HashMap(java.util.HashMap) DataCollection(org.apache.shindig.protocol.DataCollection) ExpandoColumn(com.liferay.portlet.expando.model.ExpandoColumn) UserId(org.apache.shindig.social.opensocial.spi.UserId) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ExpandoColumn

use of com.liferay.portlet.expando.model.ExpandoColumn in project sw360portal by sw360.

the class CustomFieldHelper method ensureUserCustomFieldExists.

private static void ensureUserCustomFieldExists(com.liferay.portal.model.User liferayUser, String customFieldName, int customFieldType) throws PortalException, SystemException {
    ExpandoBridge exp = liferayUser.getExpandoBridge();
    if (!exp.hasAttribute(customFieldName)) {
        exp.addAttribute(customFieldName, customFieldType, false);
        long companyId = liferayUser.getCompanyId();
        ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(companyId, exp.getClassName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, customFieldName);
        String[] roleNames = new String[] { RoleConstants.USER, RoleConstants.POWER_USER };
        for (String roleName : roleNames) {
            Role role = RoleLocalServiceUtil.getRole(companyId, roleName);
            if (role != null && column != null) {
                ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, ExpandoColumn.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(column.getColumnId()), role.getRoleId(), new String[] { ActionKeys.VIEW, ActionKeys.UPDATE });
            }
        }
    }
}
Also used : Role(com.liferay.portal.model.Role) ExpandoColumn(com.liferay.portlet.expando.model.ExpandoColumn) ExpandoBridge(com.liferay.portlet.expando.model.ExpandoBridge)

Example 3 with ExpandoColumn

use of com.liferay.portlet.expando.model.ExpandoColumn in project liferay-ide by liferay.

the class LiferayAppDataService method doUpdatePersonData.

protected void doUpdatePersonData(UserId userId, GroupId groupId, String appId, Set<String> fields, Map<String, String> values, SecurityToken securityToken) throws Exception {
    long companyId = getCompanyId(securityToken);
    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
    for (String key : values.keySet()) {
        // Workaround for a Shindig bug that stores a Long in value instead
        // of the expected String so we cannot use generics here
        String value = String.valueOf(values.get(key));
        ExpandoColumn expandoColumn = getExpandoColumn(companyId, getColumnName(appId, key));
        ExpandoValueLocalServiceUtil.addValue(companyId, User.class.getName(), ShindigUtil.getTableOpenSocial(), expandoColumn.getName(), userIdLong, value);
    }
    return;
}
Also used : User(com.liferay.portal.model.User) ExpandoColumn(com.liferay.portlet.expando.model.ExpandoColumn)

Example 4 with ExpandoColumn

use of com.liferay.portlet.expando.model.ExpandoColumn in project liferay-ide by liferay.

the class LiferayAppDataService method getExpandoColumn.

protected ExpandoColumn getExpandoColumn(long companyId, String columnName) throws Exception {
    ExpandoTable expandoTable = null;
    try {
        expandoTable = ExpandoTableLocalServiceUtil.getTable(companyId, User.class.getName(), ShindigUtil.getTableOpenSocial());
    } catch (NoSuchTableException nste) {
        _log.error(nste, nste);
    }
    ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(expandoTable.getTableId(), columnName);
    if (expandoColumn == null) {
        expandoColumn = ExpandoColumnLocalServiceUtil.addColumn(expandoTable.getTableId(), columnName, ExpandoColumnConstants.STRING);
    }
    return expandoColumn;
}
Also used : ExpandoTable(com.liferay.portlet.expando.model.ExpandoTable) ExpandoColumn(com.liferay.portlet.expando.model.ExpandoColumn) NoSuchTableException(com.liferay.portlet.expando.NoSuchTableException)

Example 5 with ExpandoColumn

use of com.liferay.portlet.expando.model.ExpandoColumn in project liferay-ide by liferay.

the class LiferayAppDataService method doDeletePersonData.

protected void doDeletePersonData(UserId userId, GroupId groupId, String appId, Set<String> fields, SecurityToken securityToken) throws Exception {
    long companyId = getCompanyId(securityToken);
    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
    for (String field : fields) {
        ExpandoColumn expandoColumn = getExpandoColumn(companyId, getColumnName(appId, field));
        ExpandoValueLocalServiceUtil.deleteValue(companyId, User.class.getName(), ShindigUtil.getTableOpenSocial(), expandoColumn.getName(), userIdLong);
    }
    return;
}
Also used : User(com.liferay.portal.model.User) ExpandoColumn(com.liferay.portlet.expando.model.ExpandoColumn)

Aggregations

ExpandoColumn (com.liferay.portlet.expando.model.ExpandoColumn)6 Role (com.liferay.portal.model.Role)2 User (com.liferay.portal.model.User)2 ExpandoTable (com.liferay.portlet.expando.model.ExpandoTable)2 HashMap (java.util.HashMap)2 Layout (com.liferay.portal.model.Layout)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 NoSuchTableException (com.liferay.portlet.expando.NoSuchTableException)1 ExpandoBridge (com.liferay.portlet.expando.model.ExpandoBridge)1 Map (java.util.Map)1 DataCollection (org.apache.shindig.protocol.DataCollection)1 UserId (org.apache.shindig.social.opensocial.spi.UserId)1