/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.dtls.fairdatapoint.service.impl;

import nl.dtls.fairdatapoint.domain.StoreManager;
import nl.dtls.fairdatapoint.service.DataAccessorService;
import nl.dtls.fairdatapoint.service.DataAccessorServiceException;
import nl.dtls.fairdatapoint.service.impl.utils.RDFUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openrdf.model.Statement;
import org.openrdf.repository.RepositoryResult;
import org.openrdf.rio.RDFFormat;

/**
 *
 * @author Rajaram Kaliyaperumal
 * @since 2016-01-07
 * @version 0.1
 */
public class DataAccessorServiceImpl implements DataAccessorService {
    
    private final static Logger LOGGER 
            = LogManager.getLogger(DataAccessorServiceImpl.class);
    
    private final StoreManager storeManager;
    private final String BASE_URI;
    
    public DataAccessorServiceImpl(StoreManager storeManager, String baseURI) {
        this.storeManager = storeManager;
        this.BASE_URI = baseURI;
        if(this.storeManager == null) {
            LOGGER.debug("The storeManager is NULL");
        }
        if(baseURI == null || baseURI.isEmpty()) {
            LOGGER.debug("The base URI is NULL (or) empty string");
        }
    }

    @Override
    public String retrieveDatasetDistribution(String catalogID, 
            String datasetID, String distributionID, RDFFormat format) 
            throws DataAccessorServiceException {        
        String datasetDistributionURI = this.BASE_URI.concat("fdp").concat("/").
                concat(catalogID).concat("/").concat(datasetID).
                concat("/").concat(distributionID);
        String datasetDistribution = null;
        try {
            RepositoryResult<Statement> statements = 
                    storeManager.retrieveResource(datasetDistributionURI);
            if(statements != null) {
                datasetDistribution = 
                        RDFUtils.writeToString(statements, format);
            }
            storeManager.closeRepositoryConnection();
        } catch (Exception ex) {
            LOGGER.error("Error retrieving dataset metadata of <" + 
                    datasetDistributionURI + ">");
            throw(new DataAccessorServiceException(ex.getMessage()));
        }
        return datasetDistribution;        
    } 
    
}

@@ -1223,47 +1223,152 @@
     
-LOGGER.debug(%22The storeManager is NULL%22
+String errorMsg = %22The storeManager can't be NULL%22;%0A            LOGGER.error(errorMsg);%0A            throw(new IllegalArgumentException(errorMsg)
 );%0A 
@@ -1443,21 +1443,26 @@
     
-LOGGER.debug(
+String errorMsg = 
 %22The
@@ -1474,16 +1474,25 @@
  URI is 
+can't be 
 NULL (or
@@ -1506,16 +1506,110 @@
  string%22
+;%0A            LOGGER.error(errorMsg);%0A            throw(new IllegalArgumentException(errorMsg)
 );%0A     
@@ -1822,22 +1822,925 @@
 tion %7B  
+%0A
       
+  %0A        if(format == null) %7B%0A            String errorMsg = %22The RDFFormat can't be NULL%22;%0A            LOGGER.error(errorMsg);%0A            throw(new IllegalArgumentException(errorMsg));%0A        %7D%0A        if(catalogID == null %7C%7C catalogID.isEmpty()) %7B%0A            String errorMsg = %22The catalogID can't be NULL or empty%22;%0A            LOGGER.error(errorMsg);%0A            throw(new IllegalArgumentException(errorMsg));%0A        %7D%0A        if(datasetID == null %7C%7C datasetID.isEmpty()) %7B%0A            String errorMsg = %22The datasetID can't be NULL or empty%22;%0A            LOGGER.error(errorMsg);%0A            throw(new IllegalArgumentException(errorMsg));%0A        %7D%0A        if(distributionID == null %7C%7C distributionID.isEmpty()) %7B%0A            String errorMsg = %22The distributionID can't be NULL or empty%22;%0A            LOGGER.error(errorMsg);%0A            throw(new IllegalArgumentException(errorMsg));%0A        %7D
 %0A       

Check null and empty args