2015-11-19 14:39:21 -08:00
|
|
|
/**
|
|
|
|
* Copyright 2015 LinkedIn Corp. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
package utils;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
import models.LineagePathInfo;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import play.Logger;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
2016-04-21 11:43:37 -07:00
|
|
|
import java.util.List;
|
2015-11-19 14:39:21 -08:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class Lineage
|
|
|
|
{
|
|
|
|
|
|
|
|
public static final String URNIDMAPKey = "impactUrnIDMap";
|
|
|
|
|
|
|
|
public static LineagePathInfo convertFromURN(String urn)
|
|
|
|
{
|
|
|
|
if (StringUtils.isBlank(urn))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
LineagePathInfo pathInfo = new LineagePathInfo();
|
|
|
|
|
|
|
|
String[] pathArray = urn.split(":///");
|
|
|
|
if (pathArray != null && pathArray.length > 0)
|
|
|
|
{
|
|
|
|
String storageType = pathArray[0];
|
|
|
|
pathInfo.storageType = storageType;
|
|
|
|
if (StringUtils.isNotBlank(storageType))
|
|
|
|
{
|
2016-04-11 16:42:47 -07:00
|
|
|
if (pathArray.length > 1 && StringUtils.isNotBlank(pathArray[1]))
|
2015-11-19 14:39:21 -08:00
|
|
|
{
|
2016-04-11 16:42:47 -07:00
|
|
|
pathInfo.filePath = "/" + pathArray[1];
|
2016-03-14 16:27:51 -07:00
|
|
|
}
|
2015-11-19 14:39:21 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pathInfo.storageType = null;
|
|
|
|
pathInfo.schemaName = null;
|
|
|
|
pathInfo.filePath = urn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pathInfo.storageType = null;
|
|
|
|
pathInfo.schemaName = null;
|
|
|
|
pathInfo.filePath = urn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pathInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String convertToURN(LineagePathInfo pathInfo)
|
|
|
|
{
|
|
|
|
if (pathInfo == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
String filePath = "";
|
|
|
|
if (StringUtils.isNotBlank(pathInfo.filePath))
|
|
|
|
{
|
|
|
|
if(pathInfo.filePath.charAt(0) == '/')
|
|
|
|
{
|
|
|
|
filePath = pathInfo.filePath.substring(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filePath = pathInfo.filePath;
|
|
|
|
}
|
|
|
|
}
|
2016-04-18 18:08:27 -07:00
|
|
|
return pathInfo.storageType.toLowerCase() + ":///" + filePath;
|
2015-11-19 14:39:21 -08:00
|
|
|
}
|
2016-04-21 11:43:37 -07:00
|
|
|
|
|
|
|
public static boolean isInList(List<String> list, String source)
|
|
|
|
{
|
|
|
|
if (list == null || list.size() == 0 || StringUtils.isBlank(source))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for(String s : list)
|
|
|
|
{
|
|
|
|
if (source.equalsIgnoreCase(s))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-19 14:39:21 -08:00
|
|
|
}
|