Search in sources :

Example 11 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-business-process by wso2.

the class TaskOperationsImpl method getUserListForRole.

private TUser[] getUserListForRole(String roleName, int tenantId, String actualOwnerUserName) throws RegistryException, UserStoreException {
    TUser[] userList = new TUser[0];
    RegistryService registryService = HumanTaskServiceComponent.getRegistryService();
    if (registryService != null && registryService.getUserRealm(tenantId) != null) {
        UserRealm userRealm = registryService.getUserRealm(tenantId);
        String[] assignableUserNameList = userRealm.getUserStoreManager().getUserListOfRole(roleName);
        if (assignableUserNameList != null) {
            userList = new TUser[assignableUserNameList.length];
            for (int i = 0; i < assignableUserNameList.length; i++) {
                TUser user = new TUser();
                user.setTUser(assignableUserNameList[i]);
                if (StringUtils.isEmpty(actualOwnerUserName)) {
                    userList[i] = user;
                } else if (StringUtils.isNotEmpty(actualOwnerUserName) && !actualOwnerUserName.equals(assignableUserNameList[i])) {
                    userList[i] = user;
                }
            }
        }
    } else {
        log.warn("Cannot load User Realm for Tenant Id: " + tenantId);
    }
    return userList;
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) RegistryService(org.wso2.carbon.registry.core.service.RegistryService)

Example 12 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-business-process by wso2.

the class AnalyticsServerProfileBuilder method loadAnalyticsProfileFromRegistry.

/**
 * Load Analytics profile from given registry and registry path.
 *
 * @param analyticsServerProfile AnalyticsServerProfile instance
 * @param registry               Registry space where file is located
 * @param location               Registry path of the profile file
 */
private void loadAnalyticsProfileFromRegistry(AnalyticsServerProfile analyticsServerProfile, Registry registry, String location) {
    try {
        if (registry.resourceExists(location)) {
            Resource resource = registry.get(location);
            String resourceContent = new String((byte[]) resource.getContent());
            parseAnalyticsProfile(resourceContent, analyticsServerProfile);
        } else {
            String errMsg = "The resource: " + location + " does not exist.";
            handleError(errMsg);
        }
    } catch (RegistryException e) {
        String errMsg = "Error occurred while reading the resource from registry: " + location + " to build the Analytics server profile: " + profileLocation;
        handleError(errMsg, e);
    }
}
Also used : Resource(org.wso2.carbon.registry.api.Resource) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 13 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-business-process by wso2.

the class AnalyticsServerProfileBuilder method build.

/**
 * Creates AnalyticsServerProfile for given tenant and Analytic profile.
 *
 * @return AnalyticsServerProfile instance
 */
public AnalyticsServerProfile build() {
    AnalyticsServerProfile analyticsServerProfile = new AnalyticsServerProfile();
    Registry registry;
    String location;
    if (profileLocation.startsWith(UnifiedEndpointConstants.VIRTUAL_CONF_REG)) {
        try {
            registry = BPELServiceComponent.getRegistryService().getConfigSystemRegistry(tenantId);
            location = profileLocation.substring(profileLocation.indexOf(UnifiedEndpointConstants.VIRTUAL_CONF_REG) + UnifiedEndpointConstants.VIRTUAL_CONF_REG.length());
            loadAnalyticsProfileFromRegistry(analyticsServerProfile, registry, location);
        } catch (RegistryException re) {
            String errMsg = "Error while loading Analytic profile from config registry.";
            handleError(errMsg, re);
        }
    } else if (profileLocation.startsWith(UnifiedEndpointConstants.VIRTUAL_GOV_REG)) {
        try {
            registry = BPELServiceComponent.getRegistryService().getGovernanceSystemRegistry(tenantId);
            location = profileLocation.substring(profileLocation.indexOf(UnifiedEndpointConstants.VIRTUAL_GOV_REG) + UnifiedEndpointConstants.VIRTUAL_GOV_REG.length());
            loadAnalyticsProfileFromRegistry(analyticsServerProfile, registry, location);
        } catch (RegistryException re) {
            String errMsg = "Error while loading Analytic profile from governance registry.";
            handleError(errMsg, re);
        }
    } else if (profileLocation.startsWith(UnifiedEndpointConstants.VIRTUAL_REG)) {
        try {
            registry = BPELServiceComponent.getRegistryService().getLocalRepository(tenantId);
            location = profileLocation.substring(profileLocation.indexOf(UnifiedEndpointConstants.VIRTUAL_REG) + UnifiedEndpointConstants.VIRTUAL_REG.length());
            loadAnalyticsProfileFromRegistry(analyticsServerProfile, registry, location);
        } catch (RegistryException re) {
            String errMsg = "Error while loading Analytic profile from local registry";
            handleError(errMsg, re);
        }
    } else if (profileLocation.startsWith(UnifiedEndpointConstants.VIRTUAL_FILE)) {
        location = profileLocation.substring(profileLocation.indexOf(UnifiedEndpointConstants.VIRTUAL_FILE) + UnifiedEndpointConstants.VIRTUAL_FILE.length());
        loadAnalyticsProfileFromFileSystem(analyticsServerProfile, location);
    } else {
        String errMsg = "Invalid analytics profile location: " + profileLocation;
        handleError(errMsg);
    }
    return analyticsServerProfile;
}
Also used : Registry(org.wso2.carbon.registry.api.Registry) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 14 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-business-process by wso2.

the class HumanTaskPackageRepository method addLatestArchiveToRegistryCollection.

/**
 * Add latest human task package zip to the registry
 *
 * @param humanTaskDeploymentUnit
 * @param humanTaskFile
 * @throws HumanTaskStoreException
 * @throws RegistryException
 */
private void addLatestArchiveToRegistryCollection(HumanTaskDeploymentUnit humanTaskDeploymentUnit, File humanTaskFile) throws HumanTaskStoreException, RegistryException {
    FileInputStream fileInputStream = null;
    try {
        Resource latestHumanTaskArchive = configRegistry.newResource();
        fileInputStream = new FileInputStream(humanTaskFile);
        latestHumanTaskArchive.setContent(fileInputStream);
        configRegistry.put(HumanTaskPackageRepositoryUtils.getHumanTaskPackageArchiveResourcePath(humanTaskDeploymentUnit.getPackageName()), latestHumanTaskArchive);
    } catch (FileNotFoundException ex) {
        String errMsg = "HumanTask package zip file couldn't found on given location " + humanTaskFile.getAbsolutePath();
        throw new HumanTaskStoreException(errMsg, ex);
    } catch (RegistryException ex) {
        String errMsg = "Exception occurred while adding latest archive to registry collection";
        throw new RegistryException(errMsg, ex);
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                log.warn("Cannot close file input stream.", e);
            }
        }
    }
}
Also used : HumanTaskStoreException(org.wso2.carbon.humantask.core.store.HumanTaskStoreException) Resource(org.wso2.carbon.registry.core.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) FileInputStream(java.io.FileInputStream)

Example 15 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-business-process by wso2.

the class HumanTaskPackageRepository method createHumanTaskPackageParentCollectionWithProperties.

/**
 * Create parent collection for human task package using DeploymentUnitDAO
 *
 * @param deploymentUnitDAO
 * @throws RegistryException
 */
private void createHumanTaskPackageParentCollectionWithProperties(DeploymentUnitDAO deploymentUnitDAO) throws RegistryException {
    Collection humanPackage = configRegistry.newCollection();
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_CHECKSUM, deploymentUnitDAO.getChecksum());
    if (log.isDebugEnabled()) {
        log.debug(deploymentUnitDAO.getPackageName() + " updating checksum: " + deploymentUnitDAO.getChecksum() + " in registry");
    }
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_STATUS, String.valueOf(deploymentUnitDAO.getStatus()));
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_VERSION, Long.toString(deploymentUnitDAO.getVersion()));
    configRegistry.put(HumanTaskPackageRepositoryUtils.getResourcePathForHumanTaskPackage(deploymentUnitDAO), humanPackage);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Aggregations

RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)235 Resource (org.wso2.carbon.registry.core.Resource)196 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)167 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)145 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)104 Registry (org.wso2.carbon.registry.core.Registry)95 Test (org.junit.Test)81 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)81 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)75 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)70 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)67 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)61 UserStoreException (org.wso2.carbon.user.api.UserStoreException)60 API (org.wso2.carbon.apimgt.api.model.API)58 IOException (java.io.IOException)57 ArrayList (java.util.ArrayList)55 QName (javax.xml.namespace.QName)42 APIResource (org.wso2.carbon.apimgt.api.doc.model.APIResource)40 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)40 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)40