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