Class DatalakeStorageItem

java.lang.Object
com.michelin.cert.redscan.utils.datalake.DatalakeStorageItem
Direct Known Subclasses:
Brand, Domain, HttpService, Ip, IpRange, MasterDomain, Service, Vulnerability

public abstract class DatalakeStorageItem extends Object
API for interacting with ElasticSearch.
Author:
Florent BORDIGNON, Maxime ESCOURBIAC, Maxence SCHMITT, Axel REMACK
  • Field Details

    • index

      protected String index
    • parent

      protected String parent
    • blocked

      protected boolean blocked
    • data

      protected Map<String,Object> data
  • Constructor Details

    • DatalakeStorageItem

      public DatalakeStorageItem()
      DatalakeStorageItem default constructor.
  • Method Details

    • create

      public boolean create() throws DatalakeStorageException
      Create the item in Elastic searchContent.
      Returns:
      True if the creation is successful.
      Throws:
      DatalakeStorageException - Exception with the storage.
    • upsert

      public abstract boolean upsert() throws DatalakeStorageException
      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

      public boolean delete() throws DatalakeStorageException
      Delete the item from ElasticSearch.
      Returns:
      True if the deletion is successful.
      Throws:
      DatalakeStorageException - Exception with the storage.
    • upsertField

      public boolean upsertField(String key, Object value) throws DatalakeStorageException
      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

      public boolean removeField(String key) throws DatalakeStorageException
      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

      public <T extends DatalakeStorageItem> List<T> findAll() throws DatalakeStorageException
      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

      public <T extends DatalakeStorageItem> List<T> findAll(String sort) throws DatalakeStorageException
      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

      protected kong.unirest.json.JSONObject findAllContent() throws DatalakeStorageException
      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

      public <T extends DatalakeStorageItem> T find() throws DatalakeStorageException
      Get instantiated item.
      Type Parameters:
      T - DataStorageItem
      Returns:
      Item by id.
      Throws:
      DatalakeStorageException - Exception with the storage.
    • find

      public <T extends DatalakeStorageItem> T find(String id) throws DatalakeStorageException
      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

      protected kong.unirest.json.JSONObject findContent(String id) throws DatalakeStorageException
      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

      public abstract String getId()
      Item ID.
      Returns:
      Item ID.
    • getBlockId

      public String getBlockId()
      Block ID. This id is used for Block List feature.
      Returns:
      Block ID.
    • isBlocked

      public boolean isBlocked() throws DatalakeStorageException
      Determine if Datalake storage item is blocked.
      Returns:
      True if Datalake storage item is blocked.
      Throws:
      DatalakeStorageException - Exception with the storage.
    • block

      public boolean block() throws DatalakeStorageException
      Block the Datalake storage item.
      Returns:
      True if Datalake storage item was blocked.
      Throws:
      DatalakeStorageException - Exception with the storage.
    • unblock

      public boolean unblock() throws DatalakeStorageException
      Unblock the Datalake storage item.
      Returns:
      True if Datalake storage item was unblocked.
      Throws:
      DatalakeStorageException - Exception with the storage.
    • getIndex

      public String getIndex()
      Get index name. (ex: brands)
      Returns:
      Index name.
    • setIndex

      public void setIndex(String index)
      Index name.
      Parameters:
      index - Index name.
    • getParent

      public String getParent()
      Parent item id.
      Returns:
      Parent item id.
    • setParent

      public void setParent(String parent)
      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

      public Date getLastScanDate()
      Last scan date.
      Returns:
      Last scan date.
    • setLastScanDate

      public void setLastScanDate(Date lastScanDate)
      Last scan date.
      Parameters:
      lastScanDate - Last scan date.
    • toDate

      public static Date toDate(String str)
      Convert String to Date.
      Parameters:
      str - String to convert.
      Returns:
      String converted in Date.
    • fromDate

      public static String fromDate(Date date)
      Convert Date to String.
      Parameters:
      date - Date to convert.
      Returns:
      Date converted in String.
    • getData

      public Map<String,Object> getData()
      All data from elasticsearch for a datalake storage item.
      Returns:
      All data from elasticsearch for a datalake storage item.
    • setData

      public void setData(Map<String,Object> data)
      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.