Search in sources :

Example 1 with BulkImportResponse

use of org.apache.atlas.bulkimport.BulkImportResponse in project atlas by apache.

the class EntityV2JerseyResourceIT method testImportBMAttributes.

// TODO Enable this test after fixing the BulkImportResponse Deserialization issue.
@Test(dependsOnMethods = "testSubmitEntity", enabled = false)
public void testImportBMAttributes() throws AtlasServiceException {
    BulkImportResponse response = atlasClientV2.bulkUpdateBusinessAttributes(TestResourceFileUtils.getTestFilePath("template_metadata.csv"));
    assertNotNull(response);
}
Also used : BulkImportResponse(org.apache.atlas.bulkimport.BulkImportResponse) Test(org.testng.annotations.Test)

Example 2 with BulkImportResponse

use of org.apache.atlas.bulkimport.BulkImportResponse in project atlas by apache.

the class AtlasEntityStoreV2 method bulkCreateOrUpdateBusinessAttributes.

@Override
@GraphTransaction
public BulkImportResponse bulkCreateOrUpdateBusinessAttributes(InputStream inputStream, String fileName) throws AtlasBaseException {
    BulkImportResponse ret = new BulkImportResponse();
    if (StringUtils.isBlank(fileName)) {
        throw new AtlasBaseException(AtlasErrorCode.FILE_NAME_NOT_FOUND, fileName);
    }
    List<String[]> fileData = FileUtils.readFileData(fileName, inputStream);
    Map<String, AtlasEntity> attributesToAssociate = getBusinessMetadataDefList(fileData, ret);
    for (AtlasEntity entity : attributesToAssociate.values()) {
        Map<String, Map<String, Object>> businessAttributes = entity.getBusinessAttributes();
        String guid = entity.getGuid();
        try {
            addOrUpdateBusinessAttributes(guid, businessAttributes, true);
            ret.addToSuccessImportInfoList(new ImportInfo(guid, businessAttributes.toString()));
        } catch (Exception e) {
            LOG.error("Error occurred while updating BusinessMetadata Attributes for Entity " + guid);
            ret.addToFailedImportInfoList(new ImportInfo(guid, businessAttributes.toString(), FAILED, e.getMessage()));
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) BulkImportResponse(org.apache.atlas.bulkimport.BulkImportResponse) ImportInfo(org.apache.atlas.bulkimport.BulkImportResponse.ImportInfo) Map(java.util.Map) HashMap(java.util.HashMap) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) IOException(java.io.IOException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 3 with BulkImportResponse

use of org.apache.atlas.bulkimport.BulkImportResponse in project atlas by apache.

the class GlossaryServiceTest method testInvalidFileException.

@Test
public void testInvalidFileException() {
    InputStream inputStream = getFile(EXCEL_FILES, "invalid_xls.xls");
    try {
        BulkImportResponse bulkImportResponse = glossaryService.importGlossaryData(inputStream, "invalid_xls.xls");
        fail("Error occurred : Failed to recognize the invalid xls file.");
    } catch (AtlasBaseException e) {
        assertEquals(e.getMessage(), "Invalid XLS file");
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BulkImportResponse(org.apache.atlas.bulkimport.BulkImportResponse) Test(org.testng.annotations.Test)

Example 4 with BulkImportResponse

use of org.apache.atlas.bulkimport.BulkImportResponse in project atlas by apache.

the class GlossaryServiceTest method testImportGlossaryData.

@Test(dependsOnGroups = "Glossary.CREATE")
public void testImportGlossaryData() {
    try {
        InputStream inputStream = getFile(CSV_FILES, "template_1.csv");
        BulkImportResponse bulkImportResponse = glossaryService.importGlossaryData(inputStream, "template_1.csv");
        assertNotNull(bulkImportResponse);
        assertEquals(bulkImportResponse.getSuccessImportInfoList().size(), 1);
        InputStream inputStream1 = getFile(EXCEL_FILES, "template_1.xlsx");
        BulkImportResponse bulkImportResponse1 = glossaryService.importGlossaryData(inputStream1, "template_1.xlsx");
        assertNotNull(bulkImportResponse1);
        assertEquals(bulkImportResponse1.getSuccessImportInfoList().size(), 1);
        // With circular dependent relations
        InputStream inputStream2 = getFile(CSV_FILES, "template_with_circular_relationship.csv");
        BulkImportResponse bulkImportResponse2 = glossaryService.importGlossaryData(inputStream2, "template_with_circular_relationship.csv");
        assertNotNull(bulkImportResponse2);
        assertEquals(bulkImportResponse2.getSuccessImportInfoList().size(), 3);
        assertEquals(bulkImportResponse2.getFailedImportInfoList().size(), 0);
    } catch (AtlasBaseException e) {
        fail("The GlossaryTerm should have been created " + e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BulkImportResponse(org.apache.atlas.bulkimport.BulkImportResponse) Test(org.testng.annotations.Test)

Example 5 with BulkImportResponse

use of org.apache.atlas.bulkimport.BulkImportResponse in project atlas by apache.

the class GlossaryClientV2IT method testImportGlossaryData.

@Test()
public void testImportGlossaryData() {
    try {
        String filePath = TestResourceFileUtils.getTestFilePath("template.csv");
        BulkImportResponse terms = atlasClientV2.importGlossary(filePath);
        assertNotNull(terms);
        assertEquals(terms.getSuccessImportInfoList().size(), 1);
    } catch (AtlasServiceException ex) {
        fail("Import GlossaryData should've succeeded : " + ex);
    }
}
Also used : AtlasServiceException(org.apache.atlas.AtlasServiceException) BulkImportResponse(org.apache.atlas.bulkimport.BulkImportResponse) Test(org.testng.annotations.Test)

Aggregations

BulkImportResponse (org.apache.atlas.bulkimport.BulkImportResponse)8 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 Test (org.testng.annotations.Test)6 InputStream (java.io.InputStream)4 FileInputStream (java.io.FileInputStream)3 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 ImportInfo (org.apache.atlas.bulkimport.BulkImportResponse.ImportInfo)1 AtlasGlossaryTerm (org.apache.atlas.model.glossary.AtlasGlossaryTerm)1 BeforeTest (org.testng.annotations.BeforeTest)1