@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.proxy.config.ExternalUrls ;
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders ;
import org.apache.poi.xwpf.usermodel.XWPFDocument ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.context.annotation.Profile ;
import org.springframework.core.env.Environment ;
@ -33,6 +35,7 @@ import java.util.stream.Collectors;
@Service ( "configLoader" )
@Profile ( "devel" )
public class DevelConfigLoader implements ConfigLoader {
private static final Logger logger = LoggerFactory . getLogger ( DevelConfigLoader . class ) ;
private ExternalUrls externalUrls ;
private List < String > rdaProperties ;
@ -45,7 +48,7 @@ public class DevelConfigLoader implements ConfigLoader {
private void setExternalUrls ( ) {
String fileUrl = this . environment . getProperty ( "configuration.externalUrls" ) ;
System. out . println ( "Loaded also config file: " + fileUrl ) ;
logger. info ( "Loaded also config file: " + fileUrl ) ;
InputStream is = null ;
try {
JAXBContext jaxbContext = JAXBContext . newInstance ( ExternalUrls . class ) ;
@ -53,13 +56,12 @@ public class DevelConfigLoader implements ConfigLoader {
is = getClass ( ) . getClassLoader ( ) . getResource ( fileUrl ) . openStream ( ) ;
externalUrls = ( ExternalUrls ) jaxbUnmarshaller . unmarshal ( is ) ;
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
System . err . println ( "Cannot find resource in classpath" ) ;
logger . error ( "Cannot find resource in classpath" , ex ) ;
} finally {
try {
if ( is ! = null ) is . close ( ) ;
} catch ( IOException | NullPointerException e ) {
System. err . printl n( "Warning: Could not close a stream after reading from file: " + fileUrl ) ;
logger. war n( "Warning: Could not close a stream after reading from file: " + fileUrl , e ) ;
}
}
}
@ -77,7 +79,7 @@ public class DevelConfigLoader implements ConfigLoader {
}
reader . close ( ) ;
} catch ( IOException | NullPointerException e ) {
e. printStackTrace ( ) ;
logger. error ( e . getMessage ( ) , e ) ;
}
rdaProperties = rdaList ;
@ -90,12 +92,12 @@ public class DevelConfigLoader implements ConfigLoader {
is = getClass ( ) . getClassLoader ( ) . getResource ( filePath ) . openStream ( ) ;
this . document = new XWPFDocument ( is ) ;
} catch ( IOException | NullPointerException e ) {
e. printStackTrace ( ) ;
logger. error ( e . getMessage ( ) , e ) ;
} finally {
try {
if ( is ! = null ) is . close ( ) ;
} catch ( IOException e ) {
System. err . printl n( "Warning: Could not close a stream after reading from file: " + filePath ) ;
logger. war n( "Warning: Could not close a stream after reading from file: " + filePath , e ) ;
}
}
}
@ -108,19 +110,19 @@ public class DevelConfigLoader implements ConfigLoader {
ObjectMapper mapper = new ObjectMapper ( ) . configure ( DeserializationFeature . FAIL_ON_UNKNOWN_PROPERTIES , false ) ;
this . configurableProviders = mapper . readValue ( is , ConfigurableProviders . class ) ;
} catch ( IOException | NullPointerException e ) {
e. printStackTrace ( ) ;
logger. error ( e . getMessage ( ) , e ) ;
} finally {
try {
if ( is ! = null ) is . close ( ) ;
} catch ( IOException e ) {
System . err . printl n( "Warning: Could not close a stream after reading from file: " + filePath ) ;
logger . war n( "Warning: Could not close a stream after reading from file: " + filePath , e ) ;
}
}
}
private void setKeyToSourceMap ( ) {
String filePath = this . environment . getProperty ( "configuration.externalUrls" ) ;
System. out . println ( "Loaded also config file: " + filePath ) ;
logger. info ( "Loaded also config file: " + filePath ) ;
Document doc = getXmlDocumentFromFilePath ( filePath ) ;
if ( doc = = null ) {
this . keyToSourceMap = null ;
@ -177,14 +179,14 @@ public class DevelConfigLoader implements ConfigLoader {
doc = documentBuilder . parse ( is ) ;
return doc ;
} catch ( IOException | ParserConfigurationException | SAXException | NullPointerException e ) {
e. printStackTrace ( ) ;
logger. error ( e . getMessage ( ) , e ) ;
} finally {
try {
if ( is ! = null ) {
is . close ( ) ;
}
} catch ( IOException e ) {
System . out . printl n( "Warning: Could not close a stream after reading from file: " + filePath ) ;
logger . war n( "Warning: Could not close a stream after reading from file: " + filePath , e ) ;
}
}
return null ;
@ -197,7 +199,7 @@ public class DevelConfigLoader implements ConfigLoader {
try {
nodeList = ( NodeList ) xPath . compile ( expression ) . evaluate ( doc , XPathConstants . NODESET ) ;
} catch ( XPathExpressionException e ) {
e. printStackTrace ( ) ;
logger. error ( e . getMessage ( ) , e ) ;
}
if ( nodeList ! = null ) {
for ( int i = 0 ; i < nodeList . getLength ( ) ; i + + ) {