Search in sources :

Example 11 with DocumentationPersistenceException

use of org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException in project carbon-apimgt by wso2.

the class RegistryPersistenceDocUtil method getDocumentArtifactManager.

public static GenericArtifactManager getDocumentArtifactManager(Registry registry) throws DocumentationPersistenceException {
    GenericArtifactManager artifactManager = null;
    String key = "document";
    try {
        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
        if (GovernanceUtils.findGovernanceArtifactConfiguration(key, registry) != null) {
            artifactManager = new GenericArtifactManager(registry, key);
        } else {
            log.warn("Couldn't find GovernanceArtifactConfiguration of RXT: " + key + ". Tenant id set in registry : " + ((UserRegistry) registry).getTenantId() + ", Tenant domain set in PrivilegedCarbonContext: " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
        }
    } catch (RegistryException e) {
        String msg = "Failed to initialize GenericArtifactManager";
        log.error(msg, e);
        throw new DocumentationPersistenceException(msg, e);
    }
    return artifactManager;
}
Also used : GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 12 with DocumentationPersistenceException

use of org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException in project carbon-apimgt by wso2.

the class RegistryPersistenceDocUtil method getDocumentation.

public static Documentation getDocumentation(GenericArtifact artifact) throws DocumentationPersistenceException {
    Documentation documentation;
    try {
        DocumentationType type;
        String docType = artifact.getAttribute(APIConstants.DOC_TYPE);
        if (docType.equalsIgnoreCase(DocumentationType.HOWTO.getType())) {
            type = DocumentationType.HOWTO;
        } else if (docType.equalsIgnoreCase(DocumentationType.PUBLIC_FORUM.getType())) {
            type = DocumentationType.PUBLIC_FORUM;
        } else if (docType.equalsIgnoreCase(DocumentationType.SUPPORT_FORUM.getType())) {
            type = DocumentationType.SUPPORT_FORUM;
        } else if (docType.equalsIgnoreCase(DocumentationType.API_MESSAGE_FORMAT.getType())) {
            type = DocumentationType.API_MESSAGE_FORMAT;
        } else if (docType.equalsIgnoreCase(DocumentationType.SAMPLES.getType())) {
            type = DocumentationType.SAMPLES;
        } else {
            type = DocumentationType.OTHER;
        }
        documentation = new Documentation(type, artifact.getAttribute(APIConstants.DOC_NAME));
        documentation.setId(artifact.getId());
        documentation.setSummary(artifact.getAttribute(APIConstants.DOC_SUMMARY));
        String visibilityAttr = artifact.getAttribute(APIConstants.DOC_VISIBILITY);
        Documentation.DocumentVisibility documentVisibility = Documentation.DocumentVisibility.API_LEVEL;
        if (visibilityAttr != null) {
            if (visibilityAttr.equals(Documentation.DocumentVisibility.API_LEVEL.name())) {
                documentVisibility = Documentation.DocumentVisibility.API_LEVEL;
            } else if (visibilityAttr.equals(Documentation.DocumentVisibility.PRIVATE.name())) {
                documentVisibility = Documentation.DocumentVisibility.PRIVATE;
            } else if (visibilityAttr.equals(Documentation.DocumentVisibility.OWNER_ONLY.name())) {
                documentVisibility = Documentation.DocumentVisibility.OWNER_ONLY;
            }
        }
        documentation.setVisibility(documentVisibility);
        Documentation.DocumentSourceType docSourceType = Documentation.DocumentSourceType.INLINE;
        String artifactAttribute = artifact.getAttribute(APIConstants.DOC_SOURCE_TYPE);
        if (Documentation.DocumentSourceType.URL.name().equals(artifactAttribute)) {
            docSourceType = Documentation.DocumentSourceType.URL;
            documentation.setSourceUrl(artifact.getAttribute(APIConstants.DOC_SOURCE_URL));
        } else if (Documentation.DocumentSourceType.FILE.name().equals(artifactAttribute)) {
            docSourceType = Documentation.DocumentSourceType.FILE;
            documentation.setFilePath(prependWebContextRoot(artifact.getAttribute(APIConstants.DOC_FILE_PATH)));
        } else if (Documentation.DocumentSourceType.MARKDOWN.name().equals(artifactAttribute)) {
            docSourceType = Documentation.DocumentSourceType.MARKDOWN;
        }
        documentation.setSourceType(docSourceType);
        if (documentation.getType() == DocumentationType.OTHER) {
            documentation.setOtherTypeName(artifact.getAttribute(APIConstants.DOC_OTHER_TYPE_NAME));
        }
    } catch (GovernanceException e) {
        throw new DocumentationPersistenceException("Failed to get documentation from artifact", e);
    }
    return documentation;
}
Also used : DocumentationType(org.wso2.carbon.apimgt.persistence.dto.DocumentationType) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) Documentation(org.wso2.carbon.apimgt.persistence.dto.Documentation) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException)

Example 13 with DocumentationPersistenceException

use of org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException in project carbon-apimgt by wso2.

the class RegistryPersistenceImpl method getDocumentation.

@Override
public Documentation getDocumentation(Organization org, String apiId, String docId) throws DocumentationPersistenceException {
    Documentation documentation = null;
    boolean tenantFlowStarted = false;
    try {
        String requestedTenantDomain = org.getName();
        RegistryHolder holder = getRegistry(requestedTenantDomain);
        Registry registryType = holder.getRegistry();
        tenantFlowStarted = holder.isTenantFlowStarted();
        GenericArtifactManager artifactManager = RegistryPersistenceDocUtil.getDocumentArtifactManager(registryType);
        GenericArtifact artifact = artifactManager.getGenericArtifact(docId);
        if (artifact == null) {
            return documentation;
        }
        if (null != artifact) {
            documentation = RegistryPersistenceDocUtil.getDocumentation(artifact);
            documentation.setCreatedDate(registryType.get(artifact.getPath()).getCreatedTime());
            Date lastModified = registryType.get(artifact.getPath()).getLastModified();
            if (lastModified != null) {
                documentation.setLastUpdated(registryType.get(artifact.getPath()).getLastModified());
            }
        }
    } catch (RegistryException | APIPersistenceException e) {
        String msg = "Failed to get documentation details";
        throw new DocumentationPersistenceException(msg, e);
    } finally {
        if (tenantFlowStarted) {
            RegistryPersistenceUtil.endTenantFlow();
        }
    }
    return documentation;
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) Documentation(org.wso2.carbon.apimgt.persistence.dto.Documentation) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Date(java.util.Date)

Example 14 with DocumentationPersistenceException

use of org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException in project carbon-apimgt by wso2.

the class APIProviderImpl method isDocumentationExist.

@Override
public boolean isDocumentationExist(String uuid, String docName, String organization) throws APIManagementException {
    boolean exist = false;
    UserContext ctx = null;
    try {
        DocumentSearchResult result = apiPersistenceInstance.searchDocumentation(new Organization(organization), uuid, 0, 0, "name:" + docName, ctx);
        if (result != null && result.getDocumentationList() != null && !result.getDocumentationList().isEmpty()) {
            String returnDocName = result.getDocumentationList().get(0).getName();
            if (returnDocName != null && returnDocName.equals(docName)) {
                exist = true;
            }
        }
    } catch (DocumentationPersistenceException e) {
        handleException("Failed to search documentation for name " + docName, e);
    }
    return exist;
}
Also used : DocumentSearchResult(org.wso2.carbon.apimgt.persistence.dto.DocumentSearchResult) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)

Example 15 with DocumentationPersistenceException

use of org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException in project carbon-apimgt by wso2.

the class APIProviderImpl method addDocumentationContent.

@Override
public void addDocumentationContent(String uuid, String docId, String organization, DocumentationContent content) throws APIManagementException {
    DocumentContent mappedContent = null;
    try {
        mappedContent = DocumentMapper.INSTANCE.toDocumentContent(content);
        DocumentContent doc = apiPersistenceInstance.addDocumentationContent(new Organization(organization), uuid, docId, mappedContent);
    } catch (DocumentationPersistenceException e) {
        throw new APIManagementException("Error while adding content to doc " + docId);
    }
}
Also used : Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) DocumentContent(org.wso2.carbon.apimgt.persistence.dto.DocumentContent) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)

Aggregations

DocumentationPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)16 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)10 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)10 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)10 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)9 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)9 Registry (org.wso2.carbon.registry.core.Registry)9 Documentation (org.wso2.carbon.apimgt.persistence.dto.Documentation)8 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)7 Resource (org.wso2.carbon.registry.core.Resource)5 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)4 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)4 ArrayList (java.util.ArrayList)3 DocumentContent (org.wso2.carbon.apimgt.persistence.dto.DocumentContent)3 DocumentSearchResult (org.wso2.carbon.apimgt.persistence.dto.DocumentSearchResult)3 DevPortalSearchContent (org.wso2.carbon.apimgt.persistence.dto.DevPortalSearchContent)2 DocumentSearchContent (org.wso2.carbon.apimgt.persistence.dto.DocumentSearchContent)2 PublisherSearchContent (org.wso2.carbon.apimgt.persistence.dto.PublisherSearchContent)2 ResourceFile (org.wso2.carbon.apimgt.persistence.dto.ResourceFile)2 SearchContent (org.wso2.carbon.apimgt.persistence.dto.SearchContent)2