Skip to content

Instantly share code, notes, and snippets.

@migue
Created May 14, 2013 22:27
Show Gist options
  • Save migue/5580178 to your computer and use it in GitHub Desktop.
Save migue/5580178 to your computer and use it in GitHub Desktop.
Basic OSGi Gogo shell consuming a Liferay service
import java.util.List;
import com.liferay.gogo.commands.user.internal.AbstractUserManagementCommand;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalService;
import aQute.bnd.annotation.component.Component;
import aQute.bnd.annotation.component.Reference;
@Component(properties = {
"osgi.command.function=listByCompany",
"osgi.command.scope=usermanagement"
}, provide=Object.class)
public class ListUsersCommand extends AbstractUserManagementCommand {
public void listByCompany(long companyId) throws SystemException {
List<User> users = _userLocalService.getCompanyUsers(
companyId, -1, -1);
System.out.println("Users of the company " + companyId);
for (User user : users) {
System.out.println(
"\tUser " + user.getEmailAddress() + "with id " +
user.getUserId());
}
}
@Reference
public void setUserLocalService(UserLocalService userLocaService) {
_userLocalService = userLocaService;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment