public String getOrganizationIdByName(String organizationName) throws Exception { // Add AuthCache to the execution context BasicHttpContext ctx = new BasicHttpContext(); ctx.setAttribute(ClientContext.AUTH_CACHE, authCache); HttpPost post = new HttpPost( "/com.conx.bi.portal.liferay.common-portlet/api/secure/jsonws/conxbiorganizationutils/get-organization-id"); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("companyId", companyId)); params.add(new BasicNameValuePair("name", organizationName)); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); post.setEntity(entity); HttpResponse resp = httpclient.execute(targetHost, post, ctx); System.out.println("getOrganizationByName Status:[" + resp.getStatusLine() + "]"); String response = null; if (resp.getEntity() != null) { response = EntityUtils.toString(resp.getEntity()); } String id = null; System.out.println("getOrganizationByName Resp:[" + response + "]"); if (!StringUtil.contains(response, "Exception", "") && Validator.isNumber(response)) { if (!Validator.isNull(Long.valueOf(response))) id = response; } EntityUtils.consume(resp.getEntity()); return id; }
@Override public User provideUserByEmailAddress(String firstName, String lastName, String emailAddress) throws Exception { User user = getUserByEmailAddress(emailAddress); if (Validator.isNull(user)) user = addUser(firstName, lastName, emailAddress); return user; }
@Override public Role provideRole(String roleId, String roleName) throws Exception { Role role = getRoleByName(roleName); if (Validator.isNull(role)) { role = addRole(roleName); } return role; }
@Override public Organization provideOrganization(String portalOrganizationName) throws Exception { Organization org = null; String orgId = getOrganizationIdByName(portalOrganizationName); System.out.println("provideOrganization orgId:[" + orgId + "]"); if (!Validator.isNull(orgId)) { org = getOrganizationById(orgId); } else { org = addOrganization(portalOrganizationName, "0"); } return org; }
@Override public Organization getUserDefaultOrganization(String portalUserId) throws Exception { List<Organization> orgs = getOrganizationsByUserId(portalUserId); if (Validator.isNull(orgs) || orgs.isEmpty()) return null; else return orgs.get(0); }