Search in sources :

Example 1 with DocumentationType

use of org.wso2.carbon.apimgt.api.model.DocumentationType in project carbon-apimgt by wso2.

the class APIUtil method getDocumentation.

/**
 * Create the Documentation from artifact
 *
 * @param artifact Documentation artifact
 * @return Documentation
 * @throws APIManagementException if failed to create Documentation from artifact
 */
public static Documentation getDocumentation(GenericArtifact artifact) throws APIManagementException {
    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 APIManagementException("Failed to get documentation from artifact", e);
    }
    return documentation;
}
Also used : DocumentationType(org.wso2.carbon.apimgt.api.model.DocumentationType) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException)

Example 2 with DocumentationType

use of org.wso2.carbon.apimgt.api.model.DocumentationType 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 3 with DocumentationType

use of org.wso2.carbon.apimgt.api.model.DocumentationType in project carbon-apimgt by wso2.

the class AbstractAPIManager method getDocumentation.

public Documentation getDocumentation(APIIdentifier apiId, DocumentationType docType, String docName) throws APIManagementException {
    Documentation documentation = null;
    String docPath = APIUtil.getAPIDocPath(apiId) + docName;
    GenericArtifactManager artifactManager = getAPIGenericArtifactManagerFromUtil(registry, APIConstants.DOCUMENTATION_KEY);
    try {
        Resource docResource = registry.get(docPath);
        GenericArtifact artifact = artifactManager.getGenericArtifact(docResource.getUUID());
        documentation = APIUtil.getDocumentation(artifact);
    } catch (RegistryException e) {
        String msg = "Failed to get documentation details";
        throw new APIManagementException(msg, e);
    }
    return documentation;
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 4 with DocumentationType

use of org.wso2.carbon.apimgt.api.model.DocumentationType in project carbon-apimgt by wso2.

the class APIUtil method getDocumentation.

/**
 * Create the Documentation from artifact
 *
 * @param artifact Documentation artifact
 * @return Documentation
 * @throws APIManagementException if failed to create Documentation from artifact
 */
public static Documentation getDocumentation(GenericArtifact artifact, String docCreatorName) throws APIManagementException {
    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 (artifactAttribute.equals(Documentation.DocumentSourceType.MARKDOWN.name())) {
            docSourceType = Documentation.DocumentSourceType.MARKDOWN;
        } else if (artifactAttribute.equals(Documentation.DocumentSourceType.URL.name())) {
            docSourceType = Documentation.DocumentSourceType.URL;
        } else if (artifactAttribute.equals(Documentation.DocumentSourceType.FILE.name())) {
            docSourceType = Documentation.DocumentSourceType.FILE;
        }
        documentation.setSourceType(docSourceType);
        if ("URL".equals(artifact.getAttribute(APIConstants.DOC_SOURCE_TYPE))) {
            documentation.setSourceUrl(artifact.getAttribute(APIConstants.DOC_SOURCE_URL));
        }
        if (docSourceType == Documentation.DocumentSourceType.FILE) {
            String filePath = prependTenantPrefix(artifact.getAttribute(APIConstants.DOC_FILE_PATH), docCreatorName);
            documentation.setFilePath(prependWebContextRoot(filePath));
        }
        if (documentation.getType() == DocumentationType.OTHER) {
            documentation.setOtherTypeName(artifact.getAttribute(APIConstants.DOC_OTHER_TYPE_NAME));
        }
    } catch (GovernanceException e) {
        throw new APIManagementException("Failed to get documentation from artifact: " + e);
    }
    return documentation;
}
Also used : DocumentationType(org.wso2.carbon.apimgt.api.model.DocumentationType) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 Documentation (org.wso2.carbon.apimgt.api.model.Documentation)3 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)3 DocumentationType (org.wso2.carbon.apimgt.api.model.DocumentationType)2 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)1 Documentation (org.wso2.carbon.apimgt.persistence.dto.Documentation)1 DocumentationType (org.wso2.carbon.apimgt.persistence.dto.DocumentationType)1 DocumentationPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)1 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)1 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)1 Resource (org.wso2.carbon.registry.core.Resource)1 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)1