use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.
the class SearchResourceImpl method searchUsers.
/**
* @see io.apiman.manager.api.rest.ISearchResource#searchUsers(io.apiman.manager.api.beans.search.SearchCriteriaBean)
*/
@Override
public SearchResultsBean<UserSearchResult> searchUsers(SearchCriteriaBean criteria) throws InvalidSearchCriteriaException {
List<UserSearchResult> users = new ArrayList<>();
try {
// Maybe this should be a new query in the future?
List<UserBean> userBeans = query.findUsers(criteria).getBeans();
for (UserBean user : userBeans) {
users.add(new UserSearchResult(user.getUsername(), user.getFullName()));
}
SearchResultsBean<UserSearchResult> searchResultsBean = new SearchResultsBean<>();
searchResultsBean.setBeans(users);
searchResultsBean.setTotalSize(users.size());
return searchResultsBean;
} catch (StorageException e) {
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.
the class EsMarshalling method unmarshallUser.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the user
*/
public static UserBean unmarshallUser(Map<String, Object> source) {
if (source == null) {
return null;
}
UserBean bean = new UserBean();
bean.setUsername(asString(source.get("username")));
bean.setEmail(asString(source.get("email")));
bean.setFullName(asString(source.get("fullName")));
bean.setJoinedOn(asDate(source.get("joinedOn")));
postMarshall(bean);
return bean;
}
use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.
the class EsMarshallingTest method testMarshallUserBean.
/**
* Test method for {@link io.apiman.manager.api.es.EsMarshalling#marshall(io.apiman.manager.api.beans.idm.UserBean)}.
*/
@Test
public void testMarshallUserBean() throws Exception {
UserBean bean = createBean(UserBean.class);
XContentBuilder builder = EsMarshalling.marshall(bean);
Assert.assertEquals("{\"username\":\"USERNAME\",\"email\":\"EMAIL\",\"fullName\":\"FULLNAME\",\"joinedOn\":1}", Strings.toString(builder));
}
use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.
the class OrganizationService method listMembers.
public List<MemberBean> listMembers(String organizationId) throws OrganizationNotFoundException, NotAuthorizedException {
getOrg(organizationId);
return tryAction(() -> {
Set<RoleMembershipBean> memberships = query.getOrgMemberships(organizationId);
TreeMap<String, MemberBean> members = new TreeMap<>();
for (RoleMembershipBean membershipBean : memberships) {
String userId = membershipBean.getUserId();
String roleId = membershipBean.getRoleId();
RoleBean role = storage.getRole(roleId);
// Role does not exist!
if (role == null) {
continue;
}
MemberBean member = members.get(userId);
if (member == null) {
UserBean user = storage.getUser(userId);
member = new MemberBean();
member.setEmail(user.getEmail());
member.setUserId(userId);
member.setUserName(user.getFullName());
member.setRoles(new ArrayList<>());
members.put(userId, member);
}
MemberRoleBean mrb = new MemberRoleBean();
mrb.setRoleId(roleId);
mrb.setRoleName(role.getName());
member.getRoles().add(mrb);
if (member.getJoinedOn() == null || membershipBean.getCreatedOn().compareTo(member.getJoinedOn()) < 0) {
member.setJoinedOn(membershipBean.getCreatedOn());
}
}
return new ArrayList<>(members.values());
});
}
use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.
the class ActionService method approveContract.
public void approveContract(ContractActionDto action, String approverId) {
// Must exist
ContractBean contract = tryAction(() -> storage.getContract(action.getContractId()));
if (contract == null) {
throw ExceptionFactory.actionException(Messages.i18n.format("ContractDoesNotExist"));
}
// Must be in AwaitingApproval state (no need to approve otherwise!)
if (contract.getStatus() != ContractStatus.AwaitingApproval) {
throw ExceptionFactory.invalidContractStatus(ContractStatus.AwaitingApproval, contract.getStatus());
}
// We probably need an optimised query :-).
ClientVersionBean cvb = contract.getClient();
ApiVersionBean avb = contract.getApi();
OrganizationBean org = avb.getApi().getOrganization();
PlanVersionBean plan = contract.getPlan();
OrganizationBean orgA = avb.getApi().getOrganization();
OrganizationBean orgC = cvb.getClient().getOrganization();
UserBean approver = tryAction(() -> storage.getUser(approverId));
// Set the contract to approved state and send approved event.
contract.setStatus(ContractStatus.Created);
LOGGER.debug("{0} approved a contract: {1} -> {2}", approverId, contract, action);
// In the second phase we need to check the other contracts to see whether they are all in the 'ready' state
// If so, then it's ready to publish.
List<ContractBean> contracts = tryAction(() -> Streams.stream((storage.getAllContracts(org.getId(), cvb.getClient().getId(), cvb.getVersion())))).collect(Collectors.toList());
List<ContractBean> awaitingApprovalList = contracts.stream().filter(c -> c.getStatus().equals(ContractStatus.AwaitingApproval)).collect(Collectors.toList());
if (awaitingApprovalList.size() > 0) {
LOGGER.debug("A contract was approved, but {0} other contracts are still awaiting approval, " + "so client version {1} will remain in its pending state until the remaining contract approvals " + "are granted: {2}.", awaitingApprovalList.size(), cvb.getVersion(), awaitingApprovalList);
} else {
LOGGER.debug("All contracts for {0} have been approved", cvb.getVersion());
tryAction(() -> {
if (clientValidator.isReady(cvb)) {
// Set client to ready status and fire change status event
LOGGER.debug("Client set to ready as all contracts have been approved");
cvb.setStatus(ClientStatus.Ready);
clientAppService.fireClientStatusChangeEvent(cvb, ClientStatus.AwaitingApproval);
// If auto-promote, then we immediately register.
if (action.isAutoPromote()) {
LOGGER.debug("Auto approving: {0}", cvb);
registerClient(orgC.getId(), cvb.getClient().getId(), cvb.getVersion());
}
}
});
}
// storage.flush();
fireContractApprovedEvent(approver, contract, orgC, cvb, orgA, avb, plan);
}
Aggregations