use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApiDAOImpl method addDocumentInfo.
/**
* Add artifact resource meta data to an API
*
* @param apiId UUID of API
* @param documentInfo {@link DocumentInfo}
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void addDocumentInfo(String apiId, DocumentInfo documentInfo) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
ApiResourceDAO.addResourceWithoutValue(connection, apiId, documentInfo.getId(), ResourceCategory.DOC);
DocMetaDataDAO.addDocumentInfo(connection, documentInfo);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateDocumentInfo.
/**
* Add artifact resource meta data to an API
*
* @param apiId UUID of API
* @param documentInfo {@link DocumentInfo}
* @param updatedBy user who performs the action
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void updateDocumentInfo(String apiId, DocumentInfo documentInfo, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
DocMetaDataDAO.updateDocInfo(connection, documentInfo, updatedBy);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method getMockDocumentInfoObjectsList.
public static List<DocumentInfo> getMockDocumentInfoObjectsList() {
List<DocumentInfo> docList = new ArrayList<>();
DocumentInfo doc1 = new DocumentInfo.Builder().fileName("sample1").id("123").build();
DocumentInfo doc2 = new DocumentInfo.Builder().fileName("sample1").id("124").build();
DocumentInfo doc3 = new DocumentInfo.Builder().fileName("sample1").id("125").build();
docList.add(doc1);
docList.add(doc2);
docList.add(doc3);
return docList;
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testFingerprintAfterUpdatingDocument.
@Test
public void testFingerprintAfterUpdatingDocument() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
apiDAO.addDocumentInfo(api.getId(), documentInfo);
String fingerprintBeforeUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfDocument(documentInfo.getId()));
Assert.assertNotNull(fingerprintBeforeUpdate);
Thread.sleep(1);
DocumentInfo updateDocument = SampleTestObjectCreator.createAlternativeDocumentationInfo(documentInfo.getId());
apiDAO.updateDocumentInfo(api.getId(), updateDocument, ADMIN);
String fingerprintAfterUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfDocument(documentInfo.getId()));
Assert.assertNotNull(fingerprintBeforeUpdate);
Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetDocumentInlineContent.
@Test(description = "Getting document inline content for an API")
public void testGetDocumentInlineContent() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiDAO.addAPI(api);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
apiDAO.addDocumentInfo(api.getId(), documentInfo);
String inlineDocContent = SampleTestObjectCreator.createDefaultInlineDocumentationContent();
apiDAO.addDocumentInlineContent(documentInfo.getId(), inlineDocContent, ADMIN);
String inlineDocContentFromDB = apiDAO.getDocumentInlineContent(documentInfo.getId());
Assert.assertEquals(inlineDocContent, inlineDocContentFromDB);
}
Aggregations