Search in sources :

Example 1 with ClientVersionBean

use of io.apiman.manager.api.beans.clients.ClientVersionBean in project apiman by apiman.

the class OrganizationResourceImpl method getApiRegistry.

/**
 * Gets the API registry.
 * @param organizationId
 * @param clientId
 * @param version
 * @throws ClientVersionNotFoundException
 */
private ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version) throws ClientVersionNotFoundException {
    // Try to get the client first - will throw a ClientVersionNotFoundException if not found.
    ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version);
    Map<String, IGatewayLink> gatewayLinks = new HashMap<>();
    Map<String, GatewayBean> gateways = new HashMap<>();
    boolean txStarted = false;
    try {
        ApiRegistryBean apiRegistry = query.getApiRegistry(organizationId, clientId, version);
        apiRegistry.setApiKey(clientVersion.getApikey());
        List<ApiEntryBean> apis = apiRegistry.getApis();
        storage.beginTx();
        txStarted = true;
        for (ApiEntryBean api : apis) {
            String gatewayId = api.getGatewayId();
            // Don't return the gateway id.
            api.setGatewayId(null);
            GatewayBean gateway = gateways.get(gatewayId);
            if (gateway == null) {
                gateway = storage.getGateway(gatewayId);
                gateways.put(gatewayId, gateway);
            }
            IGatewayLink link = gatewayLinks.get(gatewayId);
            if (link == null) {
                link = gatewayLinkFactory.create(gateway);
                gatewayLinks.put(gatewayId, link);
            }
            ApiEndpoint se = link.getApiEndpoint(api.getApiOrgId(), api.getApiId(), api.getApiVersion());
            String apiEndpoint = se.getEndpoint();
            api.setHttpEndpoint(apiEndpoint);
        }
        return apiRegistry;
    } catch (StorageException | GatewayAuthenticationException e) {
        throw new SystemErrorException(e);
    } finally {
        if (txStarted) {
            storage.rollbackTx();
        }
        for (IGatewayLink link : gatewayLinks.values()) {
            link.close();
        }
    }
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) HashMap(java.util.HashMap) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 2 with ClientVersionBean

use of io.apiman.manager.api.beans.clients.ClientVersionBean in project apiman by apiman.

the class EsMarshalling method unmarshallClientVersion.

/**
 * Unmarshals the given map source into a bean.
 * @param source the source
 * @return the client version
 */
public static ClientVersionBean unmarshallClientVersion(Map<String, Object> source) {
    if (source == null) {
        return null;
    }
    ClientVersionBean bean = new ClientVersionBean();
    bean.setVersion(asString(source.get("version")));
    bean.setApikey(asString(source.get("apikey")));
    bean.setStatus(asEnum(source.get("status"), ClientStatus.class));
    bean.setCreatedBy(asString(source.get("createdBy")));
    bean.setCreatedOn(asDate(source.get("createdOn")));
    bean.setModifiedBy(asString(source.get("modifiedBy")));
    bean.setModifiedOn(asDate(source.get("modifiedOn")));
    bean.setPublishedOn(asDate(source.get("publishedOn")));
    bean.setRetiredOn(asDate(source.get("retiredOn")));
    postMarshall(bean);
    return bean;
}
Also used : ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus)

Example 3 with ClientVersionBean

use of io.apiman.manager.api.beans.clients.ClientVersionBean in project apiman by apiman.

the class OrganizationResourceImpl method deleteClient.

/**
 * @see IOrganizationResource#deleteClient(java.lang.String, java.lang.String)
 */
@Override
public void deleteClient(@PathParam("organizationId") String organizationId, @PathParam("clientId") String clientId) throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
    securityContext.checkPermissions(PermissionType.clientAdmin, organizationId);
    try {
        storage.beginTx();
        ClientBean client = getClientFromStorage(organizationId, clientId);
        Iterator<ClientVersionBean> clientVersions = storage.getAllClientVersions(organizationId, clientId);
        Iterable<ClientVersionBean> iterable = () -> clientVersions;
        List<ClientVersionBean> registeredElems = StreamSupport.stream(iterable.spliterator(), false).filter(clientVersion -> clientVersion.getStatus() == ClientStatus.Registered).limit(5).collect(toList());
        if (!registeredElems.isEmpty()) {
            throw ExceptionFactory.entityStillActiveExceptionClientVersions(registeredElems);
        }
        storage.deleteClient(client);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug("Deleted ClientApp: " + client.getName());
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) UpdateClientBean(io.apiman.manager.api.beans.clients.UpdateClientBean) UsagePerClientBean(io.apiman.manager.api.beans.metrics.UsagePerClientBean) ResponseStatsPerClientBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) NewClientBean(io.apiman.manager.api.beans.clients.NewClientBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) MalformedURLException(java.net.MalformedURLException) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)

Example 4 with ClientVersionBean

use of io.apiman.manager.api.beans.clients.ClientVersionBean in project apiman by apiman.

the class OrganizationResourceImpl method getClientApiKey.

/**
 * @see IOrganizationResource#getClientApiKey(java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public ApiKeyBean getClientApiKey(String organizationId, String clientId, String version) throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException {
    securityContext.checkPermissions(PermissionType.clientView, organizationId);
    ClientVersionBean client = getClientVersionInternal(organizationId, clientId, version);
    ApiKeyBean apiKeyBean = new ApiKeyBean();
    apiKeyBean.setApiKey(client.getApikey());
    return apiKeyBean;
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) ApiKeyBean(io.apiman.manager.api.beans.clients.ApiKeyBean)

Example 5 with ClientVersionBean

use of io.apiman.manager.api.beans.clients.ClientVersionBean in project apiman by apiman.

the class OrganizationResourceImpl method deleteContract.

/**
 * @see IOrganizationResource#deleteContract(java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
 */
@Override
public void deleteContract(String organizationId, String clientId, String version, Long contractId) throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException, InvalidClientStatusException {
    securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
    try {
        storage.beginTx();
        ContractBean contract = storage.getContract(contractId);
        if (contract == null) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (!contract.getClient().getClient().getOrganization().getId().equals(organizationId)) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (!contract.getClient().getClient().getId().equals(clientId)) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (!contract.getClient().getVersion().equals(version)) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (contract.getClient().getStatus() == ClientStatus.Retired) {
            throw ExceptionFactory.invalidClientStatusException();
        }
        storage.deleteContract(contract);
        storage.createAuditEntry(AuditUtils.contractBrokenFromClient(contract, securityContext));
        storage.createAuditEntry(AuditUtils.contractBrokenToApi(contract, securityContext));
        // Update the version with new meta-data (e.g. modified-by)
        ClientVersionBean clientV = getClientVersionFromStorage(organizationId, clientId, version);
        clientV.setModifiedBy(securityContext.getCurrentUser());
        clientV.setModifiedOn(new Date());
        storage.updateClientVersion(clientV);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Deleted contract: %s", contract));
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) Date(java.util.Date) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) MalformedURLException(java.net.MalformedURLException) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException) NewContractBean(io.apiman.manager.api.beans.contracts.NewContractBean) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean)

Aggregations

ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)46 NewClientVersionBean (io.apiman.manager.api.beans.clients.NewClientVersionBean)25 StorageException (io.apiman.manager.api.core.exceptions.StorageException)23 Date (java.util.Date)23 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)17 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)17 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)16 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)16 PlanVersionNotFoundException (io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException)16 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)14 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)14 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)14 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)13 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)12 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)12 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)12 ClientVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException)12 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)12 InvalidClientStatusException (io.apiman.manager.api.rest.exceptions.InvalidClientStatusException)12 InvalidNameException (io.apiman.manager.api.rest.exceptions.InvalidNameException)12