Search in sources :

Example 26 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project jaggery by wso2.

the class RegistryHostObject method jsFunction_newCollection.

public static Scriptable jsFunction_newCollection(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
    RegistryHostObject rho = (RegistryHostObject) thisObj;
    if (arguments.length == 0) {
        if (rho.registry != null) {
            try {
                Collection collection = rho.registry.newCollection();
                CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
                return cho;
            } catch (RegistryException e) {
                throw new ScriptException("Error occurred while creating a new Collection", e);
            }
        } else {
            throw new ScriptException("Registry has not initialized");
        }
    } else {
        throw new ScriptException("newCollection() Method doesn't accept arguments");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 27 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project jaggery by wso2.

the class RegistryHostObject method jsFunction_getAvgRating.

public static Number jsFunction_getAvgRating(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
    String functionName = "getAvgRating";
    int argsCount = args.length;
    if (argsCount != 1) {
        HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
    }
    RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
    if (!(args[0] instanceof String)) {
        HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
    }
    try {
        return registryHostObject.registry.getAverageRating((String) args[0]);
    } catch (RegistryException e) {
        throw new ScriptException(e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 28 with RegistryException

use of org.wso2.carbon.registry.core.exceptions.RegistryException in project jaggery by wso2.

the class ResourceHostObject method jsGet_content.

public Object jsGet_content() throws ScriptException {
    try {
        Object result = this.resource.getContent();
        String mediaType = this.resource.getMediaType();
        if (result instanceof byte[]) {
            // if mediaType is xml related one, we return an e4x xml object
            if (mediaType != null) {
                if (mediaType.matches(".*[\\/].*[xX][mM][lL].*")) {
                    return context.newObject(this, "XML", new Object[] { new String((byte[]) result) });
                }
            }
            return new String((byte[]) result);
        } else if (result instanceof String[]) {
            String[] content = (String[]) result;
            return context.newArray(this, Arrays.copyOf(content, content.length, Object[].class));
        } else {
            return Context.toObject(result, this);
        }
    } catch (RegistryException e) {
        throw new ScriptException("Registry Exception while reading content property", e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) XMLObject(org.mozilla.javascript.xml.XMLObject) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 29 with RegistryException

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

the class AbstractAPIManager method isDocumentationExist.

/**
 * Checks whether the given document already exists for the given api/product
 *
 * @param identifier API/Product Identifier
 * @param docName    Name of the document
 * @return true if document already exists for the given api/product
 * @throws APIManagementException if failed to check existence of the documentation
 */
public boolean isDocumentationExist(Identifier identifier, String docName) throws APIManagementException {
    String docPath = "";
    docPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR + RegistryConstants.PATH_SEPARATOR + docName;
    try {
        return registry.resourceExists(docPath);
    } catch (RegistryException e) {
        String msg = "Failed to check existence of the document :" + docPath;
        throw new APIManagementException(msg, e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 30 with RegistryException

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

the class AbstractAPIManager method getCustomMediationResourceFromUuid.

/**
 * Returns the mediation policy registry resource correspond to the given identifier
 *
 * @param mediationPolicyId uuid of the mediation resource
 * @return Registry resource of given identifier or null
 * @throws APIManagementException If failed to get the registry resource of given uuid
 */
@Override
public Resource getCustomMediationResourceFromUuid(String mediationPolicyId) throws APIManagementException {
    String resourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
    try {
        Resource resource = registry.get(resourcePath);
        // resource : customsequences
        if (resource instanceof Collection) {
            Collection typeCollection = (Collection) resource;
            String[] typeArray = typeCollection.getChildren();
            for (String type : typeArray) {
                Resource typeResource = registry.get(type);
                // typeResource: in/ out/ fault
                if (typeResource instanceof Collection) {
                    String[] policyArray = ((Collection) typeResource).getChildren();
                    if (policyArray.length > 0) {
                        for (String policy : policyArray) {
                            Resource mediationResource = registry.get(policy);
                            // mediationResource: eg .log_in_msg.xml
                            String resourceId = mediationResource.getUUID();
                            if (resourceId.equals(mediationPolicyId)) {
                                // registry resource
                                return mediationResource;
                            }
                        }
                    }
                }
            }
        }
    } catch (RegistryException e) {
        String msg = "Error while accessing registry objects";
        throw new APIManagementException(msg, e);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

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