agave-tags/tags-core/src/main/java/org/iplantc/service/tags/dao/TagDao.java
/**
	 * Finds a {@link Tag} for the given owner by name or uuid. UUID search  
	 * results will always be unique. Name searches will not. In the event of a  
	 * namespace conflict where the owner created a tag with the name of a tag
	 * that was also shared with them, their personal tag is always returned.
	 * 
	 * @param uuidOrName the name or uuid of the tag for which to search
	 * @param username the user whose permission must match the tag with uuid or name
	 * @return a {@link Tag} with the given uuid or name
	 * @throws TagException if unable to query
	 */
Finds a  Tag for the given owner by name or uuid. UUID search
results will always be unique. Name searches will not. In the event of a
namespace conflict where the owner created a tag with the name of a tag
that was also shared with them, their personal tag is always returned.

@param uuidOrName the name or uuid of the tag for which to search
@param username the user whose permission must match the tag with uuid or name
@return a  Tag with the given uuid or name
@throws TagException if unable to query
Finds a Tag for the given owner by name or uuid . UUID search results will always be unique . Name searches will not . In the event of a namespace conflict where the owner created a tag with the name of a tag that was also shared with them their personal tag is always returned . @param uuidOrName the name or uuid of the tag for which to search @param username the user whose permission must match the tag with uuid or name @return a Tag with the given uuid or name @throws TagException if unable to query
public Tag findByNameOrUuid(String uuidOrName, String username) throws TagException
	{
		if (StringUtils.isEmpty(uuidOrName)) {
			return null;
		}
		else {
			try
			{
				HibernateUtil.beginTransaction();
				Session session = HibernateUtil.getSession();
				session.clear();
				String hql = "from Tag t where (t.name = :uuidORName OR t.uuid = :uuidORName) and " +
						"		( " +
						"			t.owner = :owner OR \n" +
						"	        t.uuid in ( \n" +
						"               SELECT tp.entityId FROM TagPermission tp \n" +
						"               WHERE tp.username = :owner AND tp.permission <> :none AND tp.entityId = t.uuid \n" +
						"           ) \n" +
						"       )";
				List<Tag> tags = (List<Tag>)session.createQuery(hql)
						.setString("uuidORName",uuidOrName)
						.setString("owner", username)
						.setString("none", PermissionType.NONE.name())
						.setCacheMode(CacheMode.IGNORE)
						.setCacheable(false)
						.list();
				session.flush();
				if (tags.isEmpty()) {
					return null;
				} else {
					Optional<Tag> tag = tags.stream().filter(t -> t.getOwner().equals(username)).findFirst();
					return tag.orElseGet(() -> tags.get(0));
				}
			}
			catch (HibernateException ex)
			{
				try
				{
					if (HibernateUtil.getSession().isOpen()) {
						HibernateUtil.rollbackTransaction();
					}
				}
				catch (Exception ignored) {}
				throw new TagException(ex);
			}
			finally {
				try { HibernateUtil.commitTransaction(); } catch (Exception ignored) {}
			}
		}
	}
public Tag findByNameOrUuid ( String uuidOrName , String username ) throws TagException { if ( StringUtils . isEmpty ( uuidOrName ) ) { return null ; } else { try { HibernateUtil . beginTransaction ( ) ; Session session = HibernateUtil . getSession ( ) ; session . clear ( ) ; String hql = "from Tag t where (t.name = :uuidORName OR t.uuid = :uuidORName) and " + "		( " + "			t.owner = :owner OR \n" + "	        t.uuid in ( \n" + "               SELECT tp.entityId FROM TagPermission tp \n" + "               WHERE tp.username = :owner AND tp.permission <> :none AND tp.entityId = t.uuid \n" + "           ) \n" + "       )" ; List < Tag > tags = ( List < Tag > ) session . createQuery ( hql ) . setString ( "uuidORName" , uuidOrName ) . setString ( "owner" , username ) . setString ( "none" , PermissionType . NONE . name ( ) ) . setCacheMode ( CacheMode . IGNORE ) . setCacheable ( false ) . list ( ) ; session . flush ( ) ; if ( tags . isEmpty ( ) ) { return null ; } else { Optional < Tag > tag = tags . stream ( ) . filter ( t -> t . getOwner ( ) . equals ( username ) ) . findFirst ( ) ; return tag . orElseGet ( ( ) -> tags . get ( 0 ) ) ; } } catch ( HibernateException ex ) { try { if ( HibernateUtil . getSession ( ) . isOpen ( ) ) { HibernateUtil . rollbackTransaction ( ) ; } } catch ( Exception ignored ) { } throw new TagException ( ex ) ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception ignored ) { } } } }
Finds a {@link Tag} for the given owner by name or uuid.
Finds a { @link Tag } for the given owner by name or uuid .
// return the first value the user owns if it exists // otherwise return the first result