amusarra
3/28/2014 - 9:57 AM

Listato 2 Implementazione del metodo getUsersCompanyByTagName per l’interfaccia locale.

Listato 2 Implementazione del metodo getUsersCompanyByTagName per l’interfaccia locale.

public com.liferay.portal.model.UserSoap[] getUsersCompanyByTagName(long companyId, String tagName,
			Integer userStatus, int start, int end) throws PortalException,
			SystemException {

		
	SearchContext searchContext = new SearchContext();

	searchContext.setCompanyId(companyId);
	searchContext.setEntryClassNames(new String[] { User.class.getName() });

	searchContext.setStart(start);
	searchContext.setEnd(end);
	searchContext.setAndSearch(true);
		
	BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
	searchQuery.addRequiredTerm(Field.COMPANY_ID, companyId);
	searchQuery.addRequiredTerm(Field.ASSET_TAG_NAMES, tagName);
	searchQuery.addRequiredTerm(Field.STATUS, userStatus);
		
	Hits hits =  SearchEngineUtil.search(searchContext, searchQuery); 
	Tuple	tuple = UsersAdminUtil.getUsers(hits);

	if (hits.getLength() == 0) {
		throw new UsersNotFoundException("No data available for the search parameters you set.");
	}

	List<User> results = (List<User>) tuple.getObject(0);
	UserSoap[] userSoap = new UserSoap[results.size()];

		
	for (int i = 0; i < userSoap.length; i++) {
		userSoap[i] = UserSoap.toSoapModel(results.get(i));
	}
				
	return userSoap;
}