Search in sources :

Example 6 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class EsMarshalling method unmarshallOrganization.

/**
 * Unmarshals the given map source into a bean.
 * @param source the source
 * @return the organization
 */
public static OrganizationBean unmarshallOrganization(Map<String, Object> source) {
    if (source == null) {
        return null;
    }
    OrganizationBean bean = new OrganizationBean();
    bean.setId(asString(source.get("id")));
    bean.setName(asString(source.get("name")));
    bean.setDescription(asString(source.get("description")));
    bean.setCreatedOn(asDate(source.get("createdOn")));
    bean.setCreatedBy(asString(source.get("createdBy")));
    bean.setModifiedOn(asDate(source.get("modifiedOn")));
    bean.setModifiedBy(asString(source.get("modifiedBy")));
    postMarshall(bean);
    return bean;
}
Also used : OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean)

Example 7 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class EsMarshalling method marshall.

/**
 * Marshals the given bean into the given map.
 * @param bean the bean
 * @return the content builder
 * @throws StorageException when a storage problem occurs while storing a bean
 */
public static XContentBuilder marshall(ClientVersionBean bean) throws StorageException {
    try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
        ClientBean client = bean.getClient();
        OrganizationBean org = client.getOrganization();
        preMarshall(bean);
        builder.startObject().field("organizationId", org.getId()).field("organizationName", org.getName()).field("clientId", client.getId()).field("clientName", client.getName()).field("clientDescription", client.getDescription()).field("version", bean.getVersion()).field("apikey", bean.getApikey()).field("status", bean.getStatus()).field("createdBy", bean.getCreatedBy()).field("createdOn", bean.getCreatedOn().getTime()).field("modifiedBy", bean.getModifiedBy()).field("modifiedOn", bean.getModifiedOn().getTime()).field("publishedOn", bean.getPublishedOn() != null ? bean.getPublishedOn().getTime() : null).field("retiredOn", bean.getRetiredOn() != null ? bean.getRetiredOn().getTime() : null).endObject();
        postMarshall(bean);
        return builder;
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
Also used : ClientBean(io.apiman.manager.api.beans.clients.ClientBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) IOException(java.io.IOException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 8 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class EsMarshallingTest method testMarshallOrganizationBean.

/**
 * Test method for {@link io.apiman.manager.api.es.EsMarshalling#marshall(io.apiman.manager.api.beans.orgs.OrganizationBean)}.
 */
@Test
public void testMarshallOrganizationBean() throws Exception {
    OrganizationBean bean = createBean(OrganizationBean.class);
    XContentBuilder builder = EsMarshalling.marshall(bean);
    Assert.assertEquals("{\"id\":\"ID\",\"name\":\"NAME\",\"description\":\"DESCRIPTION\",\"createdBy\":\"CREATEDBY\",\"createdOn\":1,\"modifiedBy\":\"MODIFIEDBY\",\"modifiedOn\":1}", Strings.toString(builder));
}
Also used : OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test)

Example 9 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class OrganizationResourceImpl method update.

/**
 * @see IOrganizationResource#update(java.lang.String, io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)
 */
@Override
public void update(String organizationId, UpdateOrganizationBean bean) throws OrganizationNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.orgEdit, organizationId);
    try {
        storage.beginTx();
        OrganizationBean orgForUpdate = getOrganizationFromStorage(organizationId);
        EntityUpdatedData auditData = new EntityUpdatedData();
        if (AuditUtils.valueChanged(orgForUpdate.getDescription(), bean.getDescription())) {
            // $NON-NLS-1$
            auditData.addChange("description", orgForUpdate.getDescription(), bean.getDescription());
            orgForUpdate.setDescription(bean.getDescription());
        }
        storage.updateOrganization(orgForUpdate);
        storage.createAuditEntry(AuditUtils.organizationUpdated(orgForUpdate, auditData, securityContext));
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Updated organization %s: %s", orgForUpdate.getName(), orgForUpdate));
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) NewOrganizationBean(io.apiman.manager.api.beans.orgs.NewOrganizationBean) UpdateOrganizationBean(io.apiman.manager.api.beans.orgs.UpdateOrganizationBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData) 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 10 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean 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);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) UsagePerPlanBean(io.apiman.manager.api.beans.metrics.UsagePerPlanBean) NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) ResponseStatsPerPlanBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) NewOrganizationBean(io.apiman.manager.api.beans.orgs.NewOrganizationBean) UpdateOrganizationBean(io.apiman.manager.api.beans.orgs.UpdateOrganizationBean) 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)

Aggregations

OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)49 StorageException (io.apiman.manager.api.core.exceptions.StorageException)20 ContractBean (io.apiman.manager.api.beans.contracts.ContractBean)14 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)13 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)13 NewOrganizationBean (io.apiman.manager.api.beans.orgs.NewOrganizationBean)13 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)13 IOException (java.io.IOException)13 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)12 ClientBean (io.apiman.manager.api.beans.clients.ClientBean)12 UpdateOrganizationBean (io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)12 PlanVersionBean (io.apiman.manager.api.beans.plans.PlanVersionBean)10 Date (java.util.Date)10 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)9 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)9 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)8 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)8 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)8 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)8 EntityManager (javax.persistence.EntityManager)8