Changeset 7590


Ignore:
Timestamp:
Feb 18, 2019, 1:19:56 PM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2149: Batch item importers should be able to use an annotation for item identification

Implemented a way to set the identifier when creating new items. This used to work automatically before since it was handled by the column mappers for each of the identification methods. This did not work when using annotations since there are no column mappers for annotation types.

IdMethod.setIdentifierOnNewItem() method was added and implemented by the AnnotationIdMethod to make sure that the specified annotation is set on new items.

Location:
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r7588 r7590  
    766766        {
    767767          item = createItem(dc, data);
     768          idMethod.setIdentifierOnNewItem(dc, item, identifier);
    768769          if (permissionTemplateMapper != null) updatePermissions(dc, (Shareable)item, data, true);
    769770          dc.saveItem(item);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AnnotationIdMethod.java

    r7588 r7590  
    2424import java.util.List;
    2525
     26import net.sf.basedb.core.Annotatable;
     27import net.sf.basedb.core.Annotation;
    2628import net.sf.basedb.core.AnnotationType;
    2729import net.sf.basedb.core.BasicItem;
     
    117119    return query.list(dc);
    118120  }
     121 
     122  /**
     123    Set the annotation on a newly created item.
     124  */
     125  @Override
     126  public <I extends BasicItem> boolean setIdentifierOnNewItem(DbControl dc, I item, String identifier)
     127  {
     128    if (annotationType == null)
     129    {
     130      throw new NullPointerException("No annotation type has been specified for 'Annotation' identification method.");
     131    }
     132    Annotatable aItem = (Annotatable)item;
     133    Type idType = annotationType.getValueType();
     134    Annotation annotation = aItem.getAnnotationSet().getAnnotation(annotationType);
     135    boolean changed = annotation.setValueIfDifferent(idType.parseString(identifier), null);
     136    return changed;
     137  }
     138 
    119139  // ---------------------------
    120140 
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/IdMethod.java

    r4513 r7590  
    8080  public <I extends BasicItem> List<I> find(DbControl dc, ItemQuery<I> query, String identifier);
    8181
     82  /**
     83    Set the ID on a newly created item when this is not done by other regular
     84    column mappers. The default implementation of this method does nothing.
     85    @return TRUE if the identifier was set, FALSE if not
     86    @since 3.15
     87  */
     88  public default <I extends BasicItem> boolean setIdentifierOnNewItem(DbControl dc, I item, String identifier)
     89  {
     90    return false;
     91  }
     92 
    8293}
Note: See TracChangeset for help on using the changeset viewer.