use of io.apiman.manager.api.rest.exceptions.InvalidNameException in project apiman by apiman.
the class OrganizationResourceImpl method createClient.
/**
* @see IOrganizationResource#createClient(java.lang.String, io.apiman.manager.api.beans.clients.NewClientBean)
*/
@Override
public ClientBean createClient(String organizationId, NewClientBean bean) throws OrganizationNotFoundException, ClientAlreadyExistsException, NotAuthorizedException, InvalidNameException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
FieldValidator.validateName(bean.getName());
ClientBean newClient = new ClientBean();
newClient.setId(BeanUtils.idFromName(bean.getName()));
newClient.setName(bean.getName());
newClient.setDescription(bean.getDescription());
newClient.setCreatedBy(securityContext.getCurrentUser());
newClient.setCreatedOn(new Date());
try {
// Store/persist the new client
storage.beginTx();
OrganizationBean org = getOrganizationFromStorage(organizationId);
newClient.setOrganization(org);
if (storage.getClient(org.getId(), newClient.getId()) != null) {
throw ExceptionFactory.clientAlreadyExistsException(bean.getName());
}
storage.createClient(newClient);
storage.createAuditEntry(AuditUtils.clientCreated(newClient, securityContext));
if (bean.getInitialVersion() != null) {
NewClientVersionBean newClientVersion = new NewClientVersionBean();
newClientVersion.setVersion(bean.getInitialVersion());
createClientVersionInternal(newClientVersion, newClient);
}
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Created client %s: %s", newClient.getName(), newClient));
return newClient;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.InvalidNameException in project apiman by apiman.
the class OrganizationResourceImpl method createPlan.
/**
* @see IOrganizationResource#createPlan(java.lang.String,
* io.apiman.manager.api.beans.plans.NewPlanBean)
*/
@Override
public PlanBean createPlan(String organizationId, NewPlanBean bean) throws OrganizationNotFoundException, PlanAlreadyExistsException, NotAuthorizedException, InvalidNameException {
securityContext.checkPermissions(PermissionType.planEdit, organizationId);
FieldValidator.validateName(bean.getName());
PlanBean newPlan = new PlanBean();
newPlan.setName(bean.getName());
newPlan.setDescription(bean.getDescription());
newPlan.setId(BeanUtils.idFromName(bean.getName()));
newPlan.setCreatedOn(new Date());
newPlan.setCreatedBy(securityContext.getCurrentUser());
try {
// Store/persist the new plan
storage.beginTx();
OrganizationBean orgBean = getOrganizationFromStorage(organizationId);
if (storage.getPlan(orgBean.getId(), newPlan.getId()) != null) {
throw ExceptionFactory.planAlreadyExistsException(newPlan.getName());
}
newPlan.setOrganization(orgBean);
storage.createPlan(newPlan);
storage.createAuditEntry(AuditUtils.planCreated(newPlan, securityContext));
if (bean.getInitialVersion() != null) {
NewPlanVersionBean newPlanVersion = new NewPlanVersionBean();
newPlanVersion.setVersion(bean.getInitialVersion());
createPlanVersionInternal(newPlanVersion, newPlan);
}
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Created plan: %s", newPlan));
return newPlan;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.InvalidNameException in project apiman by apiman.
the class OrganizationResourceImpl method create.
/**
* @see IOrganizationResource#create(io.apiman.manager.api.beans.orgs.NewOrganizationBean)
*/
@Override
public OrganizationBean create(NewOrganizationBean bean) throws OrganizationAlreadyExistsException, InvalidNameException {
if (config.isAdminOnlyOrgCreationEnabled()) {
securityContext.checkAdminPermissions();
}
FieldValidator.validateName(bean.getName());
List<RoleBean> autoGrantedRoles;
SearchCriteriaBean criteria = new SearchCriteriaBean();
criteria.setPage(1);
criteria.setPageSize(100);
// $NON-NLS-1$ //$NON-NLS-2$
criteria.addFilter("autoGrant", "true", SearchCriteriaFilterOperator.bool_eq);
try {
autoGrantedRoles = query.findRoles(criteria).getBeans();
} catch (StorageException e) {
throw new SystemErrorException(e);
}
if ("true".equals(System.getProperty("apiman.manager.require-auto-granted-org", "true"))) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (autoGrantedRoles.isEmpty()) {
// $NON-NLS-1$
throw new SystemErrorException(Messages.i18n.format("OrganizationResourceImpl.NoAutoGrantRoleAvailable"));
}
}
OrganizationBean orgBean = new OrganizationBean();
orgBean.setName(bean.getName());
orgBean.setDescription(bean.getDescription());
orgBean.setId(BeanUtils.idFromName(bean.getName()));
orgBean.setCreatedOn(new Date());
orgBean.setCreatedBy(securityContext.getCurrentUser());
orgBean.setModifiedOn(new Date());
orgBean.setModifiedBy(securityContext.getCurrentUser());
try {
// Store/persist the new organization
storage.beginTx();
if (storage.getOrganization(orgBean.getId()) != null) {
throw ExceptionFactory.organizationAlreadyExistsException(bean.getName());
}
storage.createOrganization(orgBean);
storage.createAuditEntry(AuditUtils.organizationCreated(orgBean, securityContext));
// Auto-grant memberships in roles to the creator of the organization
for (RoleBean roleBean : autoGrantedRoles) {
String currentUser = securityContext.getCurrentUser();
String orgId = orgBean.getId();
RoleMembershipBean membership = RoleMembershipBean.create(currentUser, roleBean.getId(), orgId);
membership.setCreatedOn(new Date());
storage.createMembership(membership);
}
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Created organization %s: %s", orgBean.getName(), orgBean));
return orgBean;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.InvalidNameException in project apiman by apiman.
the class OrganizationResourceImpl method createApi.
/**
* @see IOrganizationResource#createApi(java.lang.String, io.apiman.manager.api.beans.apis.NewApiBean)
*/
@Override
public ApiBean createApi(String organizationId, NewApiBean bean) throws OrganizationNotFoundException, ApiAlreadyExistsException, NotAuthorizedException, InvalidNameException {
securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
FieldValidator.validateName(bean.getName());
ApiBean newApi = new ApiBean();
newApi.setName(bean.getName());
newApi.setDescription(bean.getDescription());
newApi.setId(BeanUtils.idFromName(bean.getName()));
newApi.setCreatedOn(new Date());
newApi.setCreatedBy(securityContext.getCurrentUser());
try {
GatewaySummaryBean gateway = getSingularGateway();
storage.beginTx();
OrganizationBean orgBean = getOrganizationFromStorage(organizationId);
if (storage.getApi(orgBean.getId(), newApi.getId()) != null) {
throw ExceptionFactory.apiAlreadyExistsException(bean.getName());
}
newApi.setOrganization(orgBean);
// Store/persist the new API
storage.createApi(newApi);
storage.createAuditEntry(AuditUtils.apiCreated(newApi, securityContext));
if (bean.getInitialVersion() != null) {
NewApiVersionBean newApiVersion = new NewApiVersionBean();
newApiVersion.setEndpoint(bean.getEndpoint());
newApiVersion.setEndpointType(bean.getEndpointType());
newApiVersion.setEndpointContentType(bean.getEndpointContentType());
newApiVersion.setPlans(bean.getPlans());
newApiVersion.setPublicAPI(bean.getPublicAPI());
newApiVersion.setParsePayload(bean.getParsePayload());
newApiVersion.setDisableKeysStrip(bean.getDisableKeysStrip());
newApiVersion.setVersion(bean.getInitialVersion());
newApiVersion.setDefinitionUrl(bean.getDefinitionUrl());
newApiVersion.setDefinitionType(bean.getDefinitionType());
createApiVersionInternal(newApiVersion, newApi, gateway);
}
storage.commitTx();
return newApi;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations