Search in sources :

Example 1 with DocumentVisibility

use of org.wso2.carbon.apimgt.api.model.Documentation.DocumentVisibility 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 DocumentVisibility

use of org.wso2.carbon.apimgt.api.model.Documentation.DocumentVisibility 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 DocumentVisibility

use of org.wso2.carbon.apimgt.api.model.Documentation.DocumentVisibility 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

GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 Documentation (org.wso2.carbon.apimgt.api.model.Documentation)2 DocumentationType (org.wso2.carbon.apimgt.api.model.DocumentationType)2 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