use of io.apiman.manager.api.beans.apis.NewApiBean in project apiman by apiman.
the class ApiService method createApi.
public ApiBeanDto createApi(String organizationId, NewApiBean bean) throws OrganizationNotFoundException, ApiAlreadyExistsException, NotAuthorizedException, InvalidNameException {
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());
newApi.setImage(bean.getImage());
newApi.setTags(tagMapper.toEntity(bean.getTags()));
return tryAction(() -> {
GatewaySummaryBean gateway = getSingularGateway();
OrganizationBean orgBean = organizationService.getOrg(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());
newApiVersion.setExtendedDescription(bean.getExtendedDescription());
createApiVersionInternal(newApiVersion, newApi, gateway);
}
return apiMapper.toDto(newApi);
});
}
use of io.apiman.manager.api.beans.apis.NewApiBean 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