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;
}
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;
}
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;
}
Aggregations