use of com.google.cloud.asset.v1.ContentType in project java-asset by googleapis.
the class ListAssets method testListAssetsExample.
@Test
public void testListAssetsExample() throws Exception {
// Use the default project Id (configure it by setting environment variable
// "GOOGLE_CLOUD_PROJECT").
String projectId = ServiceOptions.getDefaultProjectId();
String[] assetTypes = { "storage.googleapis.com/Bucket", "bigquery.googleapis.com/Table" };
ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED;
ListAssetsExample.listAssets(projectId, assetTypes, contentType);
String got = bout.toString();
if (!got.isEmpty()) {
assertThat(got).contains("asset");
}
}
use of com.google.cloud.asset.v1.ContentType in project java-asset by googleapis.
the class ListAssets method testListAssetsRelationshipExample.
@Test
public void testListAssetsRelationshipExample() throws Exception {
// Use the default project Id (configure it by setting environment variable
// "GOOGLE_CLOUD_PROJECT").
String projectId = ServiceOptions.getDefaultProjectId();
String[] assetTypes = { "compute.googleapis.com/Instance", "compute.googleapis.com/Disk" };
ContentType contentType = ContentType.RELATIONSHIP;
ListAssetsExample.listAssets(projectId, assetTypes, contentType);
String got = bout.toString();
if (!got.isEmpty()) {
assertThat(got).contains("asset");
}
}
use of com.google.cloud.asset.v1.ContentType in project eec by wangguanquan.
the class ExcelReader method checkContentType.
// --- PRIVATE FUNCTIONS
private ContentType checkContentType(Path root) {
SAXReader reader = new SAXReader();
Document document;
// Read [Content_Types].xml
try {
document = reader.read(Files.newInputStream(root.resolve("[Content_Types].xml")));
} catch (DocumentException | IOException e) {
FileUtil.rm_rf(root.toFile(), true);
throw new ExcelReadException("The file format is incorrect or corrupted. [[Content_Types].xml]");
}
ContentType contentType = new ContentType();
List<Element> list = document.getRootElement().elements();
for (Element e : list) {
if ("Override".equals(e.getName())) {
ContentType.Override override = new ContentType.Override(e.attributeValue("ContentType"), e.attributeValue("PartName"));
if (!Files.exists(root.resolve(override.getPartName().substring(1)))) {
FileUtil.rm_rf(root.toFile(), true);
throw new ExcelReadException("The file format is incorrect or corrupted. [" + override.getPartName() + "]");
}
contentType.add(override);
}
}
return contentType;
}
use of com.google.cloud.asset.v1.ContentType in project eec by wangguanquan.
the class AbstractTemplate method bindSheetData.
protected int bindSheetData() {
// Read content
Path contentTypePath = zipPath.resolve("[Content_Types].xml");
SAXReader reader = new SAXReader();
Document document;
try {
document = reader.read(Files.newInputStream(contentTypePath));
} catch (DocumentException | IOException e) {
// read style file fail.
wb.what("9002", "[Content_Types].xml");
return 0;
}
// Find Override
List<Element> overrides = document.getRootElement().elements("Override");
int[] result = overrides.stream().filter(e -> Const.ContentType.SHEET.equals(e.attributeValue("ContentType"))).map(e -> zipPath.resolve(e.attributeValue("PartName").substring(1))).mapToInt(this::bindSheet).toArray();
int n = 0;
for (int i : result) n += i;
return n;
}
use of com.google.cloud.asset.v1.ContentType in project eec by wangguanquan.
the class AbstractTemplate method check.
/**
* The open-xml legitimate check
*
* @return true if legitimate
*/
public boolean check() {
// Integrity check
Path contentTypePath = zipPath.resolve("[Content_Types].xml");
SAXReader reader = new SAXReader();
Document document;
try {
document = reader.read(Files.newInputStream(contentTypePath));
} catch (DocumentException | IOException e) {
wb.what("9002", "[Content_Types].xml");
return false;
}
List<ContentType.Override> overrides = new ArrayList<>();
List<ContentType.Default> defaults = new ArrayList<>();
Iterator<Element> it = document.getRootElement().elementIterator();
while (it.hasNext()) {
Element e = it.next();
if ("Override".equals(e.getName())) {
overrides.add(new ContentType.Override(e.attributeValue("ContentType"), e.attributeValue("PartName")));
} else if ("Default".equals(e.getName())) {
defaults.add(new ContentType.Default(e.attributeValue("ContentType"), e.attributeValue("Extension")));
}
}
return checkDefault(defaults) && checkOverride(overrides);
}
Aggregations