Changeset 8053


Ignore:
Timestamp:
Aug 2, 2022, 1:15:28 PM (10 months ago)
Author:
Nicklas Nordborg
Message:

Fixes #2280: Change history logging when editing project-specific annotations

Location:
branches/3.19-stable/src/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3.19-stable/src/core/common-queries.xml

    r7997 r8053  
    27522752  <query id="DBLOG_GET_ANNOTATIONTYPE_INFO" type="HQL">
    27532753    <sql>
    2754       SELECT at.name, at.valueType, at.disableLogOfValues
     2754      SELECT at.name, at.valueType, at.disableLogOfValues, at.projectAnnotations
    27552755      FROM AnnotationTypeData at
    27562756      WHERE at.id = :annotationTypeId
    27572757    </sql>
    27582758    <description>
    2759       An HQL query that loads the 'name', 'valueType' and 'disableLogOfValues' flag
    2760       for an annotation type given the ID.
     2759      An HQL query that loads the 'name', 'valueType', 'disableLogOfValues' and
     2760      the 'projectAnnotations' flag for an annotation type given the ID.
    27612761    </description>
    27622762  </query>
  • branches/3.19-stable/src/core/net/sf/basedb/core/AnnotationBatcher.java

    r7522 r8053  
    10681068   
    10691069    /**
     1070      Get the id of the project this annotation belong to.
     1071      Only relevant if the annotation type is using project-specific
     1072      annotations.
     1073      @since 3.19.4
     1074    */
     1075    public int getProjectId()
     1076    {
     1077      return projectId;
     1078    }
     1079   
     1080    /**
    10701081      Get the ID of the unit this annotation is using.
    10711082    */
  • branches/3.19-stable/src/core/net/sf/basedb/core/log/TransactionDetails.java

    r7950 r8053  
    2323
    2424import java.util.Date;
     25import java.util.HashMap;
     26import java.util.Map;
    2527
    2628import org.hibernate.query.Query;
     
    5254  private String pluginName;
    5355  private String jobName;
     56  private Map<Integer, String> projectNames;
    5457 
    5558  /**
     
    179182
    180183  /**
     184    Get the name of the project with the given id.
     185    Special cases: 0 = default
     186  */
     187  public String getProjectName(int projectId)
     188  {
     189    String name = null;
     190    if (projectId > 0)
     191    {
     192      if (projectNames == null)
     193      {
     194        projectNames = new HashMap<>();
     195      }
     196      else
     197      {
     198        name = projectNames.get(projectId);
     199      }
     200      if (name == null)
     201      {
     202        Query<String> query = logControl.createHqlQuery("select prj.name from ProjectData prj where prj.id = " + projectId, String.class);
     203        name = query.uniqueResult();
     204        projectNames.put(projectId, name);
     205      }
     206    }
     207    else
     208    {
     209      name = "default";
     210    }
     211    return name;
     212  }
     213 
     214  /**
    181215    Utility method for loading the name of the currently executing plugin.
    182216    The first call to this method will lookup the name in the database
  • branches/3.19-stable/src/core/net/sf/basedb/core/log/db/AnnotationLogger.java

    r7381 r8053  
    8383    Integer parentId = null;
    8484    Integer parentType = null;
     85    Integer projectId = null;
    8586    Annotation.Source source = null;
    8687    List<?> newValues = null;
     
    105106        newValues = info.getNewValues();
    106107      }
     108      if (at.getProjectAnnotations()) projectId = info.getProjectId();
    107109    }
    108110    else if (entity instanceof AnnotationData)
     
    120122        valueType = Type.fromValue((Integer)tmp[1]);
    121123        if ((Boolean)tmp[2]) logOldPropertyValues = false;
     124        if ((Boolean)tmp[3]) projectId = annotation.getProjectId();
    122125      }
    123126      else
     
    125128        annotationType = at.getName();
    126129        valueType = Type.fromValue(at.getValueType());
     130        if (at.getProjectAnnotations()) projectId = annotation.getProjectId();
    127131        if (at.getDisableLogOfValues()) logOldPropertyValues = false;
    128132      }
     
    190194    change.setItemType(parentType);
    191195
     196    String projectInfo = "";
     197    if (projectId != null)
     198    {
     199      String projectName = logControl.getTransactionDetails().getProjectName(projectId);
     200      if (projectName != null) projectInfo = " ("+projectName+")";
     201    }
    192202    if (source == Annotation.Source.CLONED)
    193203    {
    194       change.setChangeInfo("ClonedAnnotation["+annotationType+"]");
     204      change.setChangeInfo("ClonedAnnotation["+annotationType+projectInfo+"]");
    195205    }
    196206    else if (source == Annotation.Source.INHERITED)
    197207    {
    198       change.setChangeInfo("InheritedAnnotation["+annotationType+"]");
     208      change.setChangeInfo("InheritedAnnotation["+annotationType+projectInfo+"]");
    199209    }
    200210    else
    201211    {
    202       change.setChangeInfo("Annotation["+annotationType+"]");
     212      change.setChangeInfo("Annotation["+annotationType+projectInfo+"]");
    203213    }
    204214    if (logOldPropertyValues)
Note: See TracChangeset for help on using the changeset viewer.