class FunctionService {

	public List<Function> fetchRelated(List<Function> functions) {
		for (Function function : functions) {
			// fetch related items
			function.setTenantId(ApplicationThreadLocals.getTenantId().get());
			if (function.getTenantId() != null)
				if (function.getParentId() != null && function.getParentId().getId() != null) {
					function.getParentId().setTenantId(function.getTenantId());
					Function parentId = functionRepository.findById(function.getParentId());
					if (parentId == null) {
						throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId");
					}
					function.setParentId(parentId);
				}

		}

		return functions;
	}

}