Search in sources :

Example 56 with Property

use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.

the class JMSTaskManagerFactory method createTaskManagerForService.

/**
 * Create a ServiceTaskManager for the service passed in and its corresponding JMSConnectionFactory
 *
 * @param jcf        JMS Connection factory definition
 * @param name       JMS consumer name
 * @param workerPool Shared thread pool from the Listener
 * @param svc        JNDI context properties and other general properties
 * @return JMSTaskManager instance
 */
public static JMSTaskManager createTaskManagerForService(JMSConnectionFactory jcf, String name, WorkerPool workerPool, Map<String, String> svc) {
    Map<String, String> cf = jcf.getParameters();
    JMSTaskManager stm = new JMSTaskManager();
    stm.setJmsConsumerName(name);
    stm.addJmsProperties(cf);
    stm.addJmsProperties(svc);
    stm.setConnFactoryJNDIName(getRqdStringProperty(JMSConstants.PARAM_CONFAC_JNDI_NAME, svc, cf));
    String destName = getOptionalStringProperty(JMSConstants.PARAM_DESTINATION, svc, cf);
    if (destName == null) {
        destName = name;
    }
    stm.setDestinationJNDIName(destName);
    stm.setDestinationType(getDestinationType(svc, cf));
    if (getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf) != null && getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf)) {
        stm.setDurableSubscriberClientId(getRqdStringProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID, svc, cf));
    }
    stm.setJmsSpec11(getJMSSpecVersion(svc, cf));
    stm.setTransactionality(getTransactionality(svc, cf));
    stm.setCacheUserTransaction(getOptionalBooleanProperty(BaseConstants.PARAM_CACHE_USER_TXN, svc, cf));
    stm.setUserTransactionJNDIName(getOptionalStringProperty(BaseConstants.PARAM_USER_TXN_JNDI_NAME, svc, cf));
    stm.setSessionTransacted(getOptionalBooleanProperty(JMSConstants.PARAM_SESSION_TRANSACTED, svc, cf));
    stm.setSessionAckMode(getSessionAck(svc, cf));
    stm.setMessageSelector(getOptionalStringProperty(JMSConstants.PARAM_MSG_SELECTOR, svc, cf));
    stm.setSubscriptionDurable(getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf));
    stm.setDurableSubscriberName(getOptionalStringProperty(JMSConstants.PARAM_DURABLE_SUB_NAME, svc, cf));
    stm.setCacheLevel(getCacheLevel(svc, cf));
    stm.setPubSubNoLocal(getOptionalBooleanProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL, svc, cf));
    Integer value = getOptionalIntProperty(JMSConstants.PARAM_RCV_TIMEOUT, svc, cf);
    if (value != null) {
        stm.setReceiveTimeout(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_CONCURRENT_CONSUMERS, svc, cf);
    if (value != null) {
        stm.setConcurrentConsumers(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_MAX_CONSUMERS, svc, cf);
    if (value != null) {
        stm.setMaxConcurrentConsumers(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_IDLE_TASK_LIMIT, svc, cf);
    if (value != null) {
        stm.setIdleTaskExecutionLimit(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_MAX_MSGS_PER_TASK, svc, cf);
    if (value != null) {
        stm.setMaxMessagesPerTask(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_RECON_INIT_DURATION, svc, cf);
    if (value != null) {
        stm.setInitialReconnectDuration(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_RECON_MAX_DURATION, svc, cf);
    if (value != null) {
        stm.setMaxReconnectDuration(value);
    }
    Double dValue = getOptionalDoubleProperty(JMSConstants.PARAM_RECON_FACTOR, svc, cf);
    if (dValue != null) {
        stm.setReconnectionProgressionFactor(dValue);
    }
    stm.setWorkerPool(workerPool);
    // remove processed properties from property bag
    stm.removeJmsProperties(JMSConstants.PARAM_CONFAC_JNDI_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_DESTINATION);
    stm.removeJmsProperties(JMSConstants.PARAM_JMS_SPEC_VER);
    stm.removeJmsProperties(BaseConstants.PARAM_TRANSACTIONALITY);
    stm.removeJmsProperties(BaseConstants.PARAM_CACHE_USER_TXN);
    stm.removeJmsProperties(BaseConstants.PARAM_USER_TXN_JNDI_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_SESSION_TRANSACTED);
    stm.removeJmsProperties(JMSConstants.PARAM_MSG_SELECTOR);
    stm.removeJmsProperties(JMSConstants.PARAM_SUB_DURABLE);
    stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_CACHE_LEVEL);
    stm.removeJmsProperties(JMSConstants.PARAM_PUBSUB_NO_LOCAL);
    stm.removeJmsProperties(JMSConstants.PARAM_RCV_TIMEOUT);
    stm.removeJmsProperties(JMSConstants.PARAM_CONCURRENT_CONSUMERS);
    stm.removeJmsProperties(JMSConstants.PARAM_MAX_CONSUMERS);
    stm.removeJmsProperties(JMSConstants.PARAM_IDLE_TASK_LIMIT);
    stm.removeJmsProperties(JMSConstants.PARAM_MAX_MSGS_PER_TASK);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_INIT_DURATION);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_MAX_DURATION);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_FACTOR);
    stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID);
    return stm;
}
Also used : JMSTaskManager(org.wso2.carbon.apimgt.common.jms.JMSTaskManager)

Example 57 with Property

use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.

the class JMSTaskManagerFactory method getTransactionality.

/**
 * @param svcMap JNDI context properties and other general property map
 * @param cfMap  properties defined on the JMS CF
 * @return value for the specific transactionality type
 */
private static int getTransactionality(Map<String, String> svcMap, Map<String, String> cfMap) {
    String key = BaseConstants.PARAM_TRANSACTIONALITY;
    String val = svcMap.get(key);
    if (val == null) {
        val = cfMap.get(key);
    }
    if (val == null) {
        return BaseConstants.TRANSACTION_NONE;
    } else {
        if (BaseConstants.STR_TRANSACTION_JTA.equalsIgnoreCase(val)) {
            return BaseConstants.TRANSACTION_JTA;
        } else if (BaseConstants.STR_TRANSACTION_LOCAL.equalsIgnoreCase(val)) {
            return BaseConstants.TRANSACTION_LOCAL;
        } else {
            throw new JmsRunTimeException("Invalid option : " + val + " for parameter : " + BaseConstants.STR_TRANSACTION_JTA);
        // TODO fix it
        // return 0;
        }
    }
}
Also used : JmsRunTimeException(org.wso2.carbon.apimgt.common.jms.JmsRunTimeException)

Example 58 with Property

use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.

the class APIProviderImplTest method getLCBean.

private LifecycleBean getLCBean() {
    LifecycleBean bean = new LifecycleBean();
    List<Property> lifecycleProps = new ArrayList<Property>();
    Property property1 = new Property();
    property1.setKey("registry.custom_lifecycle.checklist.option.APILifeCycle.1.item");
    String[] values1 = { "status:Created", "name:Requires re-subscription when publishing the API", "value:false", "order:1" };
    property1.setValues(values1);
    Property property2 = new Property();
    property2.setKey("registry.lifecycle.APILifeCycle.state");
    String[] values2 = { "Created" };
    property2.setValues(values2);
    Property property3 = new Property();
    property3.setKey("registry.custom_lifecycle.checklist.option.APILifeCycle.0.item.permission");
    String[] values3 = { "registry.custom_lifecycle.checklist.option.APILifeCycle.0.item.permission" };
    property3.setValues(values3);
    Property property4 = new Property();
    property4.setKey("registry.lifecycle.APILifeCycle.lastStateUpdatedTime");
    String[] values4 = { "2017-08-31 13:36:54.501" };
    property4.setValues(values4);
    Property property5 = new Property();
    property5.setKey("registry.custom_lifecycle.checklist.option.APILifeCycle.1.item.permission");
    String[] values5 = { "registry.custom_lifecycle.checklist.option.APILifeCycle.1.item.permission" };
    property5.setValues(values5);
    Property property6 = new Property();
    property6.setKey("registry.custom_lifecycle.checklist.option.APILifeCycle.0.item");
    String[] values6 = { "status:Created", "name:Deprecate old versions after publishing the API", "value:false", "order:0" };
    property6.setValues(values6);
    Property property7 = new Property();
    property7.setKey("registry.LC.name");
    String[] values7 = { "APILifeCycle" };
    property7.setValues(values7);
    lifecycleProps.add(property1);
    lifecycleProps.add(property2);
    lifecycleProps.add(property3);
    lifecycleProps.add(property4);
    lifecycleProps.add(property5);
    lifecycleProps.add(property6);
    Property[] propertyArr = new Property[lifecycleProps.size()];
    bean.setLifecycleProperties(lifecycleProps.toArray(propertyArr));
    String[] userRoles = { "publisher" };
    bean.setRolesOfUser(userRoles);
    return bean;
}
Also used : ArrayList(java.util.ArrayList) LifecycleBean(org.wso2.carbon.governance.custom.lifecycles.checklist.beans.LifecycleBean) Property(org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property)

Example 59 with Property

use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.

the class APIProviderImpl method updateRegistryResources.

/**
 * To add API/Product roles restrictions and add additional properties.
 *
 * @param artifactPath                Path of the API/Product artifact.
 * @param publisherAccessControlRoles Role specified for the publisher access control.
 * @param publisherAccessControl      Publisher Access Control restriction.
 * @param additionalProperties        Additional properties that is related with an API/Product.
 * @throws RegistryException Registry Exception.
 */
private void updateRegistryResources(String artifactPath, String publisherAccessControlRoles, String publisherAccessControl, Map<String, String> additionalProperties) throws RegistryException {
    publisherAccessControlRoles = (publisherAccessControlRoles == null || publisherAccessControlRoles.trim().isEmpty()) ? APIConstants.NULL_USER_ROLE_LIST : publisherAccessControlRoles;
    if (publisherAccessControlRoles.equalsIgnoreCase(APIConstants.NULL_USER_ROLE_LIST)) {
        publisherAccessControl = APIConstants.NO_ACCESS_CONTROL;
    }
    if (!registry.resourceExists(artifactPath)) {
        return;
    }
    Resource apiResource = registry.get(artifactPath);
    if (apiResource != null) {
        if (additionalProperties != null) {
            // Removing all the properties, before updating new properties.
            Properties properties = apiResource.getProperties();
            if (properties != null) {
                Enumeration propertyNames = properties.propertyNames();
                while (propertyNames.hasMoreElements()) {
                    String propertyName = (String) propertyNames.nextElement();
                    if (propertyName.startsWith(APIConstants.API_RELATED_CUSTOM_PROPERTIES_PREFIX)) {
                        apiResource.removeProperty(propertyName);
                    }
                }
            }
        }
        // We are changing to lowercase, as registry search only supports lower-case characters.
        apiResource.setProperty(APIConstants.PUBLISHER_ROLES, publisherAccessControlRoles.toLowerCase());
        // This property will be only used for display proposes in the Publisher UI so that the original case of
        // the roles that were specified can be maintained.
        apiResource.setProperty(APIConstants.DISPLAY_PUBLISHER_ROLES, publisherAccessControlRoles);
        apiResource.setProperty(APIConstants.ACCESS_CONTROL, publisherAccessControl);
        apiResource.removeProperty(APIConstants.CUSTOM_API_INDEXER_PROPERTY);
        if (additionalProperties != null && additionalProperties.size() != 0) {
            for (Map.Entry<String, String> entry : additionalProperties.entrySet()) {
                apiResource.setProperty((APIConstants.API_RELATED_CUSTOM_PROPERTIES_PREFIX + entry.getKey()), entry.getValue());
            }
        }
        registry.put(artifactPath, apiResource);
    }
}
Also used : Enumeration(java.util.Enumeration) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource) WorkflowProperties(org.wso2.carbon.apimgt.impl.dto.WorkflowProperties) Properties(java.util.Properties) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 60 with Property

use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.

the class APIProviderImpl method getAPILifeCycleData.

@Override
public /*
    * This method returns the lifecycle data for an API including current state,next states.
    *
    * @param apiId APIIdentifier
    * @return Map<String,Object> a map with lifecycle data
    */
Map<String, Object> getAPILifeCycleData(APIIdentifier apiId) throws APIManagementException {
    String path = APIUtil.getAPIPath(apiId);
    Map<String, Object> lcData = new HashMap<String, Object>();
    String providerTenantMode = apiId.getProviderName();
    boolean isTenantFlowStarted = false;
    try {
        String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(providerTenantMode));
        if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            isTenantFlowStarted = true;
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
        }
        Resource apiSourceArtifact = registry.get(path);
        GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
        if (artifactManager == null) {
            String errorMessage = "Failed to retrieve artifact manager when getting lifecycle data for API " + apiId;
            log.error(errorMessage);
            throw new APIManagementException(errorMessage);
        }
        GenericArtifact artifact = artifactManager.getGenericArtifact(apiSourceArtifact.getUUID());
        // Get all the actions corresponding to current state of the api artifact
        String[] actions = artifact.getAllLifecycleActions(APIConstants.API_LIFE_CYCLE);
        // Put next states into map
        lcData.put(APIConstants.LC_NEXT_STATES, actions);
        String lifeCycleState = artifact.getLifecycleState();
        lcData.put(APIConstants.LC_STATUS, lifeCycleState);
        LifecycleBean bean;
        bean = LifecycleBeanPopulator.getLifecycleBean(path, (UserRegistry) registry, configRegistry);
        if (bean != null) {
            ArrayList<CheckListItem> checkListItems = new ArrayList<CheckListItem>();
            ArrayList<String> permissionList = new ArrayList<String>();
            // Get lc properties
            Property[] lifecycleProps = bean.getLifecycleProperties();
            // Get roles of the current session holder
            String[] roleNames = bean.getRolesOfUser();
            for (Property property : lifecycleProps) {
                String propName = property.getKey();
                String[] propValues = property.getValues();
                // Check for permission properties if any exists
                if (propValues != null && propValues.length != 0) {
                    if (propName.startsWith(APIConstants.LC_PROPERTY_CHECKLIST_PREFIX) && propName.endsWith(APIConstants.LC_PROPERTY_PERMISSION_SUFFIX) && propName.contains(APIConstants.API_LIFE_CYCLE)) {
                        for (String role : roleNames) {
                            for (String propValue : propValues) {
                                String key = propName.replace(APIConstants.LC_PROPERTY_CHECKLIST_PREFIX, "").replace(APIConstants.LC_PROPERTY_PERMISSION_SUFFIX, "");
                                if (propValue.equals(role)) {
                                    permissionList.add(key);
                                } else if (propValue.startsWith(APIConstants.LC_PROPERTY_CHECKLIST_PREFIX) && propValue.endsWith(APIConstants.LC_PROPERTY_PERMISSION_SUFFIX)) {
                                    permissionList.add(key);
                                }
                            }
                        }
                    }
                }
            }
            // Check for lifecycle checklist item properties defined
            for (Property property : lifecycleProps) {
                String propName = property.getKey();
                String[] propValues = property.getValues();
                if (propValues != null && propValues.length != 0) {
                    CheckListItem checkListItem = new CheckListItem();
                    checkListItem.setVisible("false");
                    if (propName.startsWith(APIConstants.LC_PROPERTY_CHECKLIST_PREFIX) && propName.endsWith(APIConstants.LC_PROPERTY_ITEM_SUFFIX) && propName.contains(APIConstants.API_LIFE_CYCLE)) {
                        if (propValues.length > 2) {
                            for (String param : propValues) {
                                if (param.startsWith(APIConstants.LC_STATUS)) {
                                    checkListItem.setLifeCycleStatus(param.substring(7));
                                } else if (param.startsWith(APIConstants.LC_CHECK_ITEM_NAME)) {
                                    checkListItem.setName(param.substring(5));
                                } else if (param.startsWith(APIConstants.LC_CHECK_ITEM_VALUE)) {
                                    checkListItem.setValue(param.substring(6));
                                } else if (param.startsWith(APIConstants.LC_CHECK_ITEM_ORDER)) {
                                    checkListItem.setOrder(param.substring(6));
                                }
                            }
                        }
                        String key = propName.replace(APIConstants.LC_PROPERTY_CHECKLIST_PREFIX, "").replace(APIConstants.LC_PROPERTY_ITEM_SUFFIX, "");
                        if (permissionList.contains(key)) {
                            // Set visible to true if the checklist item permits
                            checkListItem.setVisible("true");
                        }
                    }
                    if (checkListItem.matchLifeCycleStatus(lifeCycleState)) {
                        checkListItems.add(checkListItem);
                    }
                }
            }
            lcData.put("items", checkListItems);
        }
    } catch (Exception e) {
        handleException(e.getMessage(), e);
    } finally {
        if (isTenantFlowStarted) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
    return lcData;
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CheckListItem(org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource) ArrayList(java.util.ArrayList) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) XMLStreamException(javax.xml.stream.XMLStreamException) GraphQLPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.GraphQLPersistenceException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) IOException(java.io.IOException) MediationPolicyPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.MediationPolicyPersistenceException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) WSDLPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) PersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException) UnsupportedPolicyTypeException(org.wso2.carbon.apimgt.api.UnsupportedPolicyTypeException) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) NotificationException(org.wso2.carbon.apimgt.impl.notification.exception.NotificationException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) MonetizationException(org.wso2.carbon.apimgt.api.MonetizationException) ThumbnailPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.ThumbnailPersistenceException) OASPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException) WorkflowException(org.wso2.carbon.apimgt.impl.workflow.WorkflowException) AsyncSpecPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.AsyncSpecPersistenceException) ParseException(org.json.simple.parser.ParseException) MalformedURLException(java.net.MalformedURLException) OMException(org.apache.axiom.om.OMException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) LifecycleBean(org.wso2.carbon.governance.custom.lifecycles.checklist.beans.LifecycleBean) JSONObject(org.json.simple.JSONObject) Property(org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property)

Aggregations

HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)32 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 Resource (org.wso2.carbon.registry.core.Resource)23 Map (java.util.Map)21 Test (org.junit.Test)21 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)21 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)17 API (org.wso2.carbon.apimgt.api.model.API)16 UserStoreException (org.wso2.carbon.user.api.UserStoreException)16 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 JSONObject (org.json.simple.JSONObject)14 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)14 List (java.util.List)13 IOException (java.io.IOException)11 QName (javax.xml.namespace.QName)11 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)11 Properties (java.util.Properties)10 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)10