Class DatalakeStorageItem
java.lang.Object
com.michelin.cert.redscan.utils.datalake.DatalakeStorageItem
- Direct Known Subclasses:
Brand,Domain,HttpService,Ip,IpRange,MasterDomain,Service,Vulnerability
API for interacting with ElasticSearch.
- Author:
- Florent BORDIGNON, Maxime ESCOURBIAC, Maxence SCHMITT, Axel REMACK
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanblock()Block the Datalake storage item.booleancreate()Create the item in Elastic searchContent.booleandelete()Delete the item from ElasticSearch.<T extends DatalakeStorageItem>
Tfind()Get instantiated item.<T extends DatalakeStorageItem>
TGet instantiated item.<T extends DatalakeStorageItem>
List<T> findAll()Get all instanciated items.<T extends DatalakeStorageItem>
List<T> Get all instanciated items with particular sorting.<T extends DatalakeStorageItem>
List<T> Get all instanciated items with pagination.<T extends DatalakeStorageItem>
List<T> Get all instanciated items with pagination and particular sorting.protected kong.unirest.json.JSONObjectGet all items.kong.unirest.json.JSONObjectfindAllContent(String page, String size) Get all items with pagination.protected kong.unirest.json.JSONObjectfindAllContent(kong.unirest.json.JSONObject sort) Get all items with particular sorting.kong.unirest.json.JSONObjectfindAllContent(kong.unirest.json.JSONObject sort, String page, String size) Get all items with pagination and particular sorting.protected kong.unirest.json.JSONObjectfindContent(String id) Get item from their id.protected abstract <T extends DatalakeStorageItem>
TfromDatalake(kong.unirest.json.JSONObject object) Create DatalakeStorageItem instance from Datalake data.static StringConvert Date to String.booleanItem's blocking status.Block ID.getData()All data from elasticsearch for a datalake storage item.abstract StringgetId()Item ID.getIndex()Get index name.Last scan date.Parent item id.booleanDetermine if Datalake storage item is blocked.booleanremoveField(String key) Delete a specific field for the item.<T extends DatalakeStorageItem>
List<T> Search items with pagination.<T extends DatalakeStorageItem>
List<T> Search items with pagination and sorting.<T extends DatalakeStorageItem>
List<T> search(kong.unirest.json.JSONObject query) Search items.<T extends DatalakeStorageItem>
List<T> Search items with sorting.protected kong.unirest.json.JSONObjectsearchContent(kong.unirest.json.JSONObject query) Search items.protected kong.unirest.json.JSONObjectsearchContent(kong.unirest.json.JSONObject query, String page, String size) Search items with pagination.protected kong.unirest.json.JSONObjectsearchContent(kong.unirest.json.JSONObject query, String page, String size, kong.unirest.json.JSONObject sort) Search items with pagination and sorting.protected kong.unirest.json.JSONObjectsearchContent(kong.unirest.json.JSONObject query, kong.unirest.json.JSONObject sort) Search items with sorting.voidsetBlocked(boolean blocked) Item's blocking status.voidAll data from elasticsearch for a datalake storage item.voidIndex name.voidsetLastScanDate(Date lastScanDate) Last scan date.voidParent item id.static DateConvert String to Date.booleanunblock()Unblock the Datalake storage item.abstract booleanupsert()Upsert the item in Elastic searchContent.booleanupsertField(String key, Object value) Insert or Update a specific field for the item.
-
Field Details
-
index
-
parent
-
blocked
protected boolean blocked -
data
-
-
Constructor Details
-
DatalakeStorageItem
public DatalakeStorageItem()DatalakeStorageItem default constructor.
-
-
Method Details
-
create
Create the item in Elastic searchContent.- Returns:
- True if the creation is successful.
- Throws:
DatalakeStorageException- Exception with the storage.
-
upsert
Upsert the item in Elastic searchContent. This operation cannot be mutualized and must be defined in each children classes.- Returns:
- True if the upsert is successful.
- Throws:
DatalakeStorageException- Exception with the storage.
-
delete
Delete the item from ElasticSearch.- Returns:
- True if the deletion is successful.
- Throws:
DatalakeStorageException- Exception with the storage.
-
upsertField
Insert or Update a specific field for the item.- Parameters:
key- Key to upsert.value- Value to upsert.- Returns:
- True if the upsertion was successful.
- Throws:
DatalakeStorageException- Exception with the storage.
-
removeField
Delete a specific field for the item.- Parameters:
key- Key to delete.- Returns:
- True if the deletion was successful.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAll
Get all instanciated items.- Type Parameters:
T- DataStorageItem- Returns:
- List of all instanciated items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAll
public <T extends DatalakeStorageItem> List<T> findAll(String page, String size) throws DatalakeStorageException Get all instanciated items with pagination.- Type Parameters:
T- DataStorageItem- Parameters:
page- Page number.size- Number of items in each page.- Returns:
- List of all instanciated items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAll
Get all instanciated items with particular sorting.- Type Parameters:
T- DataStorageItem.- Parameters:
sort- Elastic sort query.- Returns:
- List of all instanciated items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAll
public <T extends DatalakeStorageItem> List<T> findAll(String sort, String page, String size) throws DatalakeStorageException Get all instanciated items with pagination and particular sorting.- Type Parameters:
T- DataStorageItem.- Parameters:
sort- Elastic sort query.page- Page number.size- Number of items in each page.- Returns:
- List of all instanciated items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAllContent
Get all items.- Returns:
- All items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAllContent
protected kong.unirest.json.JSONObject findAllContent(kong.unirest.json.JSONObject sort) throws DatalakeStorageException Get all items with particular sorting.- Parameters:
sort- Elastic sort query.- Returns:
- All items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAllContent
public kong.unirest.json.JSONObject findAllContent(String page, String size) throws DatalakeStorageException Get all items with pagination.- Parameters:
page- Page number.size- Number of items in each page.- Returns:
- All items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findAllContent
public kong.unirest.json.JSONObject findAllContent(kong.unirest.json.JSONObject sort, String page, String size) throws DatalakeStorageException Get all items with pagination and particular sorting.- Parameters:
sort- Elastic sort query.page- Page number.size- Number of items in each page.- Returns:
- All items.
- Throws:
DatalakeStorageException- Exception with the storage.
-
find
Get instantiated item.- Type Parameters:
T- DataStorageItem- Returns:
- Item by id.
- Throws:
DatalakeStorageException- Exception with the storage.
-
find
Get instantiated item.- Type Parameters:
T- DataStorageItem.- Parameters:
id- Specific ID.- Returns:
- Item by id.
- Throws:
DatalakeStorageException- Exception with the storage.
-
search
public <T extends DatalakeStorageItem> List<T> search(kong.unirest.json.JSONObject query) throws DatalakeStorageException Search items.- Type Parameters:
T- DataStorageItem- Parameters:
query- Elastic searchContent query.- Returns:
- DataStorageItem instanciated corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
search
public <T extends DatalakeStorageItem> List<T> search(kong.unirest.json.JSONObject query, String sort) throws DatalakeStorageException Search items with sorting.- Type Parameters:
T- DataStorageItem- Parameters:
query- Elastic searchContent query.sort- Elastic sort query.- Returns:
- DataStorageItem instanciated corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
search
public <T extends DatalakeStorageItem> List<T> search(String page, String size, kong.unirest.json.JSONObject query) throws DatalakeStorageException Search items with pagination.- Type Parameters:
T- DataStorageItem- Parameters:
page- Page number.size- Number of items in each page.query- Elastic searchContent query.- Returns:
- DataStorageItem instanciated corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
search
public <T extends DatalakeStorageItem> List<T> search(String page, String size, kong.unirest.json.JSONObject query, String sort) throws DatalakeStorageException Search items with pagination and sorting.- Type Parameters:
T- DataStorageItem- Parameters:
page- Page number.size- Number of items in each page.query- Elastic searchContent query.sort- Elastic sort query.- Returns:
- DataStorageItem instanciated corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
findContent
Get item from their id.- Parameters:
id- Specific ID.- Returns:
- Item by id.
- Throws:
DatalakeStorageException- Exception with the storage.
-
searchContent
protected kong.unirest.json.JSONObject searchContent(kong.unirest.json.JSONObject query) throws DatalakeStorageException Search items.- Parameters:
query- Elastic searchContent query.- Returns:
- Objects corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
searchContent
protected kong.unirest.json.JSONObject searchContent(kong.unirest.json.JSONObject query, kong.unirest.json.JSONObject sort) throws DatalakeStorageException Search items with sorting.- Parameters:
query- Elastic searchContent query.sort- Elastic sort query.- Returns:
- Objects corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
searchContent
protected kong.unirest.json.JSONObject searchContent(kong.unirest.json.JSONObject query, String page, String size) throws DatalakeStorageException Search items with pagination.- Parameters:
query- Elastic searchContent query.page- Page number.size- Number of items in each page.- Returns:
- Objects corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
searchContent
protected kong.unirest.json.JSONObject searchContent(kong.unirest.json.JSONObject query, String page, String size, kong.unirest.json.JSONObject sort) throws DatalakeStorageException Search items with pagination and sorting.- Parameters:
query- Elastic searchContent query.page- Page number.size- Number of items in each page.sort- Elastic sort query.- Returns:
- Objects corresponding to the query.
- Throws:
DatalakeStorageException- Exception with the storage.
-
getId
Item ID.- Returns:
- Item ID.
-
getBlockId
Block ID. This id is used for Block List feature.- Returns:
- Block ID.
-
isBlocked
Determine if Datalake storage item is blocked.- Returns:
- True if Datalake storage item is blocked.
- Throws:
DatalakeStorageException- Exception with the storage.
-
block
Block the Datalake storage item.- Returns:
- True if Datalake storage item was blocked.
- Throws:
DatalakeStorageException- Exception with the storage.
-
unblock
Unblock the Datalake storage item.- Returns:
- True if Datalake storage item was unblocked.
- Throws:
DatalakeStorageException- Exception with the storage.
-
getIndex
Get index name. (ex: brands)- Returns:
- Index name.
-
setIndex
Index name.- Parameters:
index- Index name.
-
getParent
Parent item id.- Returns:
- Parent item id.
-
setParent
Parent item id.- Parameters:
parent- Parent item id.
-
getBlocked
public boolean getBlocked()Item's blocking status.- Returns:
- Item's blocking status.
-
setBlocked
public void setBlocked(boolean blocked) Item's blocking status.- Parameters:
blocked- Item's blocking status.
-
getLastScanDate
Last scan date.- Returns:
- Last scan date.
-
setLastScanDate
Last scan date.- Parameters:
lastScanDate- Last scan date.
-
toDate
Convert String to Date.- Parameters:
str- String to convert.- Returns:
- String converted in Date.
-
fromDate
Convert Date to String.- Parameters:
date- Date to convert.- Returns:
- Date converted in String.
-
getData
All data from elasticsearch for a datalake storage item.- Returns:
- All data from elasticsearch for a datalake storage item.
-
setData
All data from elasticsearch for a datalake storage item.- Parameters:
data- All data from elasticsearch for a datalake storage item.
-
fromDatalake
protected abstract <T extends DatalakeStorageItem> T fromDatalake(kong.unirest.json.JSONObject object) Create DatalakeStorageItem instance from Datalake data. Be careful to verify if the JSON object parameter is not null. If object is null => return null.- Type Parameters:
T- DatalakeStorageItem children.- Parameters:
object- Datalake data.- Returns:
- DatalakeStorageItem instantiated.
-