| 
									
										
										
										
											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;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  | import java.util.List;
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | import org.apache.commons.lang3.StringUtils;
 | 
					
						
							| 
									
										
										
										
											2017-09-05 09:59:35 -07:00
										 |  |  | import wherehows.models.table.LineagePathInfo;
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  | public class Lineage {
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |   public static final String URNIDMAPKey = "impactUrnIDMap";
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |   public static LineagePathInfo convertFromURN(String urn) {
 | 
					
						
							|  |  |  |     if (StringUtils.isBlank(urn)) {
 | 
					
						
							|  |  |  |       return null;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |     LineagePathInfo pathInfo = new LineagePathInfo();
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |     String[] pathArray = urn.split(":///");
 | 
					
						
							|  |  |  |     if (pathArray != null && pathArray.length > 0) {
 | 
					
						
							|  |  |  |       String storageType = pathArray[0];
 | 
					
						
							|  |  |  |       pathInfo.storageType = storageType;
 | 
					
						
							|  |  |  |       if (StringUtils.isNotBlank(storageType)) {
 | 
					
						
							|  |  |  |         if (pathArray.length > 1 && StringUtils.isNotBlank(pathArray[1])) {
 | 
					
						
							|  |  |  |           pathInfo.filePath = "/" + pathArray[1];
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							|  |  |  |           pathInfo.storageType = null;
 | 
					
						
							|  |  |  |           pathInfo.schemaName = null;
 | 
					
						
							|  |  |  |           pathInfo.filePath = urn;
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |       } else {
 | 
					
						
							|  |  |  |         pathInfo.storageType = null;
 | 
					
						
							|  |  |  |         pathInfo.schemaName = null;
 | 
					
						
							|  |  |  |         pathInfo.filePath = urn;
 | 
					
						
							|  |  |  |       }
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |     return pathInfo;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |   public static String convertToURN(LineagePathInfo pathInfo) {
 | 
					
						
							|  |  |  |     if (pathInfo == null) {
 | 
					
						
							|  |  |  |       return null;
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2016-04-21 11:43:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |     String filePath = "";
 | 
					
						
							|  |  |  |     if (StringUtils.isNotBlank(pathInfo.filePath)) {
 | 
					
						
							|  |  |  |       if (pathInfo.filePath.charAt(0) == '/') {
 | 
					
						
							|  |  |  |         filePath = pathInfo.filePath.substring(1);
 | 
					
						
							|  |  |  |       } else {
 | 
					
						
							|  |  |  |         filePath = pathInfo.filePath;
 | 
					
						
							|  |  |  |       }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  |     return pathInfo.storageType.toLowerCase() + ":///" + filePath;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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;
 | 
					
						
							|  |  |  |       }
 | 
					
						
							| 
									
										
										
										
											2016-04-21 11:43:37 -07:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2017-08-15 16:59:41 -07:00
										 |  |  |     return false;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | }
 |