summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-01-23 16:50:47 +0000
committerliamfallon <liam.fallon@est.tech>2020-01-23 16:50:51 +0000
commitf8000a9d35928f136216be504828ef9074dfb42a (patch)
tree5e81379c3eef8af54ff557cd641ab94faa426713 /model
parent755eb9df282d80273043a2e902e2a51bf6eaab24 (diff)
Remove apex-pdp TextFileUtils class
This class was moved to policy-common some time ago. Removing it in apex-pdp. Issue-ID: POLICY-1913 Change-Id: I982fbd799334b34f1526e19f339236b52205b91e Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'model')
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java45
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java53
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java4
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java10
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java11
-rw-r--r--model/utilities/pom.xml10
-rw-r--r--model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java115
-rw-r--r--model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java18
-rw-r--r--model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java9
9 files changed, 82 insertions, 193 deletions
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java
index 1f820ef68..b593b3e9f 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,8 +43,8 @@ import org.eclipse.persistence.jaxb.MarshallerProperties;
import org.eclipse.persistence.oxm.MediaType;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
-import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.common.utils.validation.Assertions;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -92,8 +92,7 @@ public class ApexModelReader<C extends AxConcept> {
// Set up the unmarshaller to carry out validation
unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
- }
- catch (final JAXBException e) {
+ } catch (final JAXBException e) {
LOGGER.error("Unable to set JAXB context", e);
throw new ApexModelException("Unable to set JAXB context", e);
}
@@ -123,16 +122,14 @@ public class ApexModelReader<C extends AxConcept> {
try {
// Set the concept schema
final URL schemaUrl = ResourceUtils.getUrlResource(schemaFileName);
- final Schema apexConceptSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
- .newSchema(schemaUrl);
+ final Schema apexConceptSchema =
+ SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaUrl);
unmarshaller.setSchema(apexConceptSchema);
- }
- catch (final Exception e) {
+ } catch (final Exception e) {
LOGGER.error("Unable to load schema ", e);
throw new ApexModelException("Unable to load schema", e);
}
- }
- else {
+ } else {
// Clear the schema
unmarshaller.setSchema(null);
}
@@ -167,8 +164,7 @@ public class ApexModelReader<C extends AxConcept> {
String apexConceptString = null;
try {
apexConceptString = TextFileUtils.getReaderAsString(apexConceptReader).trim();
- }
- catch (final IOException e) {
+ } catch (final IOException e) {
throw new ApexModelException("Unable to read Apex concept ", e);
}
@@ -201,8 +197,7 @@ public class ApexModelReader<C extends AxConcept> {
final StreamSource source = new StreamSource(new StringReader(apexString));
final JAXBElement<C> rootElement = unmarshaller.unmarshal(source, rootConceptClass);
apexConcept = rootElement.getValue();
- }
- catch (final JAXBException e) {
+ } catch (final JAXBException e) {
throw new ApexModelException("Unable to unmarshal Apex concept ", e);
}
@@ -214,14 +209,12 @@ public class ApexModelReader<C extends AxConcept> {
final AxValidationResult validationResult = apexConcept.validate(new AxValidationResult());
if (validationResult.isValid()) {
return apexConcept;
- }
- else {
+ } else {
String message = "Apex concept validation failed" + validationResult.toString();
LOGGER.error(message);
throw new ApexModelException(message);
}
- }
- else {
+ } else {
// No validation check
return apexConcept;
}
@@ -254,27 +247,23 @@ public class ApexModelReader<C extends AxConcept> {
private void setInputType(final String apexConceptString) throws ApexModelException {
// Check the input type
if (Pattern.compile(JSON_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) {
- //is json
+ // is json
try {
unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
unmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- }
- catch (final Exception e) {
+ } catch (final Exception e) {
LOGGER.warn("JAXB error setting marshaller for JSON Input", e);
throw new ApexModelException("JAXB error setting unmarshaller for JSON input", e);
}
- }
- else if (Pattern.compile(XML_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) {
- //is xml
+ } else if (Pattern.compile(XML_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) {
+ // is xml
try {
unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
- }
- catch (final Exception e) {
+ } catch (final Exception e) {
LOGGER.warn("JAXB error setting marshaller for XML Input", e);
throw new ApexModelException("JAXB error setting unmarshaller for XML input", e);
}
- }
- else {
+ } else {
LOGGER.warn("format of input for Apex concept is neither JSON nor XML");
throw new ApexModelException("format of input for Apex concept is neither JSON nor XML");
}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
index da14e810a..8acf3fc45 100644
--- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
+
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -54,8 +55,8 @@ import org.onap.policy.apex.model.policymodel.handling.PolicyAnalysisResult;
import org.onap.policy.apex.model.policymodel.handling.PolicyModelComparer;
import org.onap.policy.apex.model.policymodel.handling.PolicyModelMerger;
import org.onap.policy.apex.model.policymodel.handling.PolicyModelSplitter;
-import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.common.utils.validation.Assertions;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -105,7 +106,7 @@ public class ModelHandlerFacade {
if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS,
- MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
+ MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
}
ApexApiResult result = new ApexApiResult();
@@ -126,7 +127,7 @@ public class ModelHandlerFacade {
if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS,
- MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
+ MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
}
ApexApiResult result = new ApexApiResult();
@@ -170,13 +171,13 @@ public class ModelHandlerFacade {
* @return the result of the operation
*/
public ApexApiResult loadFromDatabase(final String modelName, final String modelVersion,
- final DaoParameters daoParameters) {
+ final DaoParameters daoParameters) {
Assertions.argumentNotNull(modelName, "modelName may not be null");
Assertions.argumentNotNull(daoParameters, "DaoParameters may not be null");
if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS,
- MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
+ MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
}
ApexDao apexDao = null;
@@ -186,8 +187,8 @@ public class ModelHandlerFacade {
// Single specific model requested
if (modelVersion != null) {
- AxPolicyModel daoPolicyModel = apexDao.get(AxPolicyModel.class,
- new AxArtifactKey(modelName, modelVersion));
+ AxPolicyModel daoPolicyModel =
+ apexDao.get(AxPolicyModel.class, new AxArtifactKey(modelName, modelVersion));
if (daoPolicyModel != null) {
apexModel.setPolicyModel(daoPolicyModel);
@@ -195,7 +196,7 @@ public class ModelHandlerFacade {
} else {
apexModel.setPolicyModel(new AxPolicyModel());
return new ApexApiResult(ApexApiResult.Result.FAILED, "no policy model with name " + modelName
- + " and version " + modelVersion + FOUND_IN_DATABASE);
+ + " and version " + modelVersion + FOUND_IN_DATABASE);
}
}
// Fishing expedition
@@ -229,7 +230,7 @@ public class ModelHandlerFacade {
foundPolicyModel = dbPolicyModel;
} else {
return new ApexApiResult(ApexApiResult.Result.FAILED,
- "more than one policy model with name " + modelName + FOUND_IN_DATABASE);
+ "more than one policy model with name " + modelName + FOUND_IN_DATABASE);
}
}
}
@@ -240,7 +241,7 @@ public class ModelHandlerFacade {
} else {
apexModel.setPolicyModel(new AxPolicyModel());
return new ApexApiResult(ApexApiResult.Result.FAILED,
- "no policy model with name " + modelName + FOUND_IN_DATABASE);
+ "no policy model with name " + modelName + FOUND_IN_DATABASE);
}
}
@@ -279,7 +280,7 @@ public class ModelHandlerFacade {
if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS,
- MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
+ MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
}
URL apexModelUrl;
@@ -364,7 +365,7 @@ public class ModelHandlerFacade {
result.setResult(ApexApiResult.Result.FAILED);
}
result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
- .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
+ .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
result.addMessage(validationResult.toString());
return result;
} catch (Exception e) {
@@ -388,10 +389,10 @@ public class ModelHandlerFacade {
return result;
}
- PolicyModelComparer policyModelComparer = new PolicyModelComparer(apexModel.getPolicyModel(),
- otherPolicyModel);
+ PolicyModelComparer policyModelComparer =
+ new PolicyModelComparer(apexModel.getPolicyModel(), otherPolicyModel);
result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
- .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
+ .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
result.addMessage(policyModelComparer.toString());
return result;
@@ -409,7 +410,7 @@ public class ModelHandlerFacade {
* @return the result of the operation
*/
public ApexApiResult compareWithString(final String otherModelString, final boolean diffsOnly,
- final boolean keysOnly) {
+ final boolean keysOnly) {
ApexApiResult result = new ApexApiResult();
try {
AxPolicyModel otherPolicyModel = loadModelFromString(otherModelString, result);
@@ -417,10 +418,10 @@ public class ModelHandlerFacade {
return result;
}
- PolicyModelComparer policyModelComparer = new PolicyModelComparer(apexModel.getPolicyModel(),
- otherPolicyModel);
+ PolicyModelComparer policyModelComparer =
+ new PolicyModelComparer(apexModel.getPolicyModel(), otherPolicyModel);
result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
- .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
+ .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
result.addMessage(policyModelComparer.toString());
return result;
@@ -453,13 +454,13 @@ public class ModelHandlerFacade {
requiredPolicySet.add(requiredPolicy.getKey());
} else {
return new ApexApiResult(ApexApiResult.Result.FAILED,
- "policy for policy name " + policyName + " not found in model");
+ "policy for policy name " + policyName + " not found in model");
}
}
try {
- AxPolicyModel splitPolicyModel = PolicyModelSplitter.getSubPolicyModel(apexModel.getPolicyModel(),
- requiredPolicySet, false);
+ AxPolicyModel splitPolicyModel =
+ PolicyModelSplitter.getSubPolicyModel(apexModel.getPolicyModel(), requiredPolicySet, false);
ApexModelFileWriter<AxPolicyModel> apexModelFileWriter = new ApexModelFileWriter<>(false);
apexModelFileWriter.apexModelWriteJsonFile(splitPolicyModel, AxPolicyModel.class, targetModelName);
@@ -497,7 +498,7 @@ public class ModelHandlerFacade {
return splitResult;
} catch (Exception e) {
return new ApexApiResult(ApexApiResult.Result.FAILED,
- "split of policy model " + apexModel.getPolicyModel().getId() + " failed", e);
+ "split of policy model " + apexModel.getPolicyModel().getId() + " failed", e);
} finally {
if (tempSplitPolicyFile != null) {
try {
@@ -527,7 +528,7 @@ public class ModelHandlerFacade {
try {
AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(apexModel.getPolicyModel(),
- mergeInPolicyModel, keepOriginal, false, false);
+ mergeInPolicyModel, keepOriginal, false, false);
apexModel.setPolicyModel(mergedPolicyModel != null ? mergedPolicyModel : new AxPolicyModel());
return new ApexApiResult();
} catch (ApexModelException e) {
@@ -554,7 +555,7 @@ public class ModelHandlerFacade {
try {
AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(apexModel.getPolicyModel(),
- mergeInPolicyModel, keepOriginal, false, false);
+ mergeInPolicyModel, keepOriginal, false, false);
apexModel.setPolicyModel(mergedPolicyModel != null ? mergedPolicyModel : new AxPolicyModel());
return new ApexApiResult();
} catch (ApexModelException e) {
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
index df5e54ca9..e6d948f35 100644
--- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,10 +38,11 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
-import org.onap.policy.apex.model.utilities.TextFileUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Test the apex model API.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ApexModelApiTest {
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
index 9bbba1d99..cfbf1be57 100644
--- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -31,10 +32,11 @@ import java.util.Properties;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.modelapi.impl.ModelHandlerFacade;
-import org.onap.policy.apex.model.utilities.TextFileUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Test the model handler facade.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ModelHandlerFacadeTest {
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java
index 8b0396bc2..cfebf19a5 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -31,9 +32,7 @@ import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
-import org.onap.policy.apex.model.policymodel.handling.PolicyComparer;
-import org.onap.policy.apex.model.policymodel.handling.PolicyModelComparer;
-import org.onap.policy.apex.model.utilities.TextFileUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
public class PolicyModelComparerTest {
diff --git a/model/utilities/pom.xml b/model/utilities/pom.xml
index 801174524..eb650a84c 100644
--- a/model/utilities/pom.xml
+++ b/model/utilities/pom.xml
@@ -1,6 +1,7 @@
<!--
============LICENSE_START=======================================================
Copyright (C) 2018 Ericsson. All rights reserved.
+ Modifications Copyright (C) 2020 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,7 +18,10 @@
SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.apex-pdp.model</groupId>
@@ -29,6 +33,10 @@
<dependencies>
<dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7.1</version>
diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java
deleted file mode 100644
index 23efd9136..000000000
--- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.utilities;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.file.Files;
-
-/**
- * The Class TextFileUtils is class that provides useful functions for handling text files. Functions to read and wrtie
- * text files to strings and strings are provided.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public abstract class TextFileUtils {
- private static final int READER_CHAR_BUFFER_SIZE_4096 = 4096;
-
- private TextFileUtils() {
- // This class cannot be initialized
- }
-
- /**
- * Method to return the contents of a text file as a string.
- *
- * @param textFilePath The path to the file as a string
- * @return A string containing the contents of the file
- * @throws IOException on errors reading text from the file
- */
- public static String getTextFileAsString(final String textFilePath) throws IOException {
- final File textFile = new File(textFilePath);
- return new String(Files.readAllBytes(textFile.toPath()));
- }
-
- /**
- * Method to write contents of a string to a text file.
- *
- * @param outString The string to write
- * @param textFilePath The path to the file as a string
- * @throws IOException on errors reading text from the file
- */
- public static void putStringAsTextFile(final String outString, final String textFilePath) throws IOException {
- final File textFile = new File(textFilePath);
- if (!textFile.getParentFile().exists()) {
- textFile.getParentFile().mkdirs();
- }
-
- putStringAsFile(outString, textFile);
- }
-
- /**
- * Method to write contents of a string to a text file.
- *
- * @param outString The string to write
- * @param textFile The file to write the string to
- * @throws IOException on errors reading text from the file
- */
- public static void putStringAsFile(final String outString, final File textFile) throws IOException {
- Files.write(textFile.toPath(), outString.getBytes());
- }
-
- /**
- * Method to return the contents of a text steam as a string.
- *
- * @param textStream The stream
- * @return A string containing the output of the stream as text
- * @throws IOException on errors reading text from the file
- */
- public static String getStreamAsString(final InputStream textStream) throws IOException {
- return getReaderAsString(new BufferedReader(new InputStreamReader(textStream)));
- }
-
- /**
- * Method to return the contents of a reader steam as a string. This closes the reader after use
- *
- * @param textReader The reader
- * @return A string containing the output of the reader as text
- * @throws IOException on errors reading text from the file
- */
- public static String getReaderAsString(final BufferedReader textReader) throws IOException {
-
- final StringBuilder builder = new StringBuilder();
- int charsRead = -1;
- final char[] chars = new char[READER_CHAR_BUFFER_SIZE_4096];
- do {
- charsRead = textReader.read(chars, 0, chars.length);
- if (charsRead > 0) {
- builder.append(chars, 0, charsRead);
- }
- }
- while (charsRead > 0);
- return builder.toString();
- }
-}
diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java
index 95839cd72..c1d255c28 100644
--- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java
+++ b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java
@@ -1,19 +1,20 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -26,26 +27,25 @@ import java.nio.file.Files;
import java.util.Arrays;
import org.junit.Test;
-import org.onap.policy.apex.model.utilities.DirectoryUtils;
-import org.onap.policy.apex.model.utilities.TextFileUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
public class DirectoryUtilsTest {
@Test
public void test() throws IOException {
DirectoryUtils.emptyDirectory(new File("/i/dont/exist"));
-
+
File tempDir = Files.createTempDirectory("test").toFile();
Files.createTempDirectory(tempDir.toPath(), "testsubprefix");
TextFileUtils.putStringAsTextFile("Temp File 0 contents", tempDir.getAbsolutePath() + "/tempFile0.tmp");
TextFileUtils.putStringAsTextFile("Temp File 1 contents", tempDir.getAbsolutePath() + "/tempFile1.tmp");
-
+
DirectoryUtils.emptyDirectory(tempDir);
-
+
DirectoryUtils.getLocalTempDirectory(null);
-
+
byte[] byteArray = new byte[] {0, 0, 0};
DirectoryUtils.getLocalTempDirectory(Arrays.toString(byteArray));
}
diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java
index d03dc7135..62f36946d 100644
--- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java
+++ b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -27,9 +28,11 @@ import java.io.FileInputStream;
import java.io.IOException;
import org.junit.Test;
+import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Test text file utilities.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class TextFileUtilsTest {