Merge remote-tracking branch 'origin/release/6.2.N' into release/6.2.N

This commit is contained in:
tzclucian
2020-10-15 11:25:06 +03:00
25 changed files with 149 additions and 29 deletions

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -9,6 +9,6 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
</project>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<profiles>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>alfresco-community-repo</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Alfresco Community Repo Parent</name>
@@ -57,8 +57,8 @@
<dependency.spring.version>5.1.15.RELEASE</dependency.spring.version>
<dependency.antlr.version>3.5.2</dependency.antlr.version>
<dependency.jackson.version>2.10.2</dependency.jackson.version>
<dependency.jackson-databind.version>2.10.1</dependency.jackson-databind.version>
<dependency.jackson.version>2.10.5</dependency.jackson.version>
<dependency.jackson-databind.version>2.10.5</dependency.jackson-databind.version>
<dependency.cxf.version>3.3.5</dependency.cxf.version>
<dependency.opencmis.version>1.0.0</dependency.opencmis.version>
<dependency.pdfbox.version>2.0.19</dependency.pdfbox.version>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -280,21 +280,28 @@ public class AuditImpl implements Audit
// clear null elements
entriesAudit.removeAll(Collections.singleton(null));
int totalItems = entriesAudit.size();
int totalRetrievedItems = entriesAudit.size();
int end = Math.min(limit - 1, totalRetrievedItems);
boolean hasMoreItems = totalRetrievedItems > end;
if (skipCount >= totalItems)
String omitTotalItemsParameter = parameters.getParameter("omitTotalItems");
boolean omitTotalItems = (null != omitTotalItemsParameter) && Boolean.parseBoolean(omitTotalItemsParameter);
Integer totalItems;
if (omitTotalItems)
{
List<AuditEntry> empty = Collections.emptyList();
return CollectionWithPagingInfo.asPaged(paging, empty, false, totalItems);
totalItems = null;
}
else
{
int end = Math.min(limit - 1, totalItems);
boolean hasMoreItems = totalItems > end;
entriesAudit = entriesAudit.subList(skipCount, end);
return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems);
totalItems = hasMoreItems ? getAuditEntriesCountByApp(auditApplication) : totalRetrievedItems;
}
entriesAudit = (skipCount >= totalRetrievedItems)
? Collections.emptyList()
: entriesAudit.subList(skipCount, end);
return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems);
}
/**
@@ -882,4 +889,10 @@ public class AuditImpl implements Audit
}
}
public int getAuditEntriesCountByApp(AuditService.AuditApplication auditApplication)
{
final String applicationName = auditApplication.getKey().substring(1);
return auditService.getAuditEntriesCountByApp(applicationName);
}
}

View File

@@ -82,9 +82,8 @@ public class JacksonHelper implements InitializingBean
//Configure the objectMapper ready for use
objectMapper = new ObjectMapper();
objectMapper.registerModule(module);
objectMapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_EMPTY);
objectMapper.configOverride(java.util.Map.class)
.setInclude(JsonInclude.Value.construct(JsonInclude.Include.NON_EMPTY, null));
objectMapper.setDefaultPropertyInclusion(
JsonInclude.Value.construct(JsonInclude.Include.NON_EMPTY, JsonInclude.Include.ALWAYS));
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
DateFormat DATE_FORMAT_ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
DATE_FORMAT_ISO8601.setTimeZone(TimeZone.getTimeZone("UTC"));

View File

@@ -26,6 +26,7 @@
package org.alfresco.rest.api.tests;
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -405,6 +406,31 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest
validateAuditEntryFields(ae, auditApp);
}
// MNT-21936 Audit query Rest API does not return the correct totalItems
int auditEntriesTotalItems = auditEntries.getPaging().getTotalItems();
// set maxItems to 1
Map<String, String> params = new HashMap<>();
params.put("maxItems","1");
auditEntries = auditAppsProxy.getAuditAppEntries(auditApp.getId(), params,
HttpServletResponse.SC_OK);
int AuditEntriesTotalItemsAfterLimit = auditEntries.getPaging().getTotalItems();
int retrievedAuditEntriesCount = auditEntries.getPaging().getCount();
// When totalItems are retrieved using getAuditEntriesCountByApp() method that was introduced in MNT-21936
// 2 audit entries will be created.
assertEquals(auditEntriesTotalItems + 2, AuditEntriesTotalItemsAfterLimit);
assertEquals(1, retrievedAuditEntriesCount);
// set omitTotalItems to true.
params.put("omitTotalItems", "true");
auditEntries = auditAppsProxy.getAuditAppEntries(auditApp.getId(), params,
HttpServletResponse.SC_OK);
// verify that totalItems is null.
assertNull(auditEntries.getPaging().getTotalItems());
// Negative tests
// 401
setRequestContext(networkOne.getId(), networkAdmin, "wrongPassword");

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>7.300-TEST4-SNAPSHOT</version>
<version>7.301-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -261,4 +261,15 @@ public interface AuditComponent
* @return a map containing min/max and the associated value
*/
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
/**
* Issue an audit query to retrieve count of records for a given application.
*
* @param applicationName the name of the application
* @return a map containing min/max and the associated value
*/
default int getAuditEntriesCountByApp(String applicationName)
{
return -1;
}
}

View File

@@ -941,4 +941,18 @@ public class AuditComponentImpl implements AuditComponent
return auditDAO.getAuditMinMaxByApp(applicationId, extremes);
}
@Override
public int getAuditEntriesCountByApp(String applicationName)
{
// Get the id for the application
AuditApplication app = auditModelRegistry.getAuditApplicationByName(applicationName);
Long applicationId = app.getApplicationId();
if (applicationId == null)
{
throw new AuditException("No persisted instance exists for audit application: " + app);
}
return auditDAO.getAuditEntriesCountByApp(applicationId);
}
}

View File

@@ -177,4 +177,13 @@ public class AuditServiceImpl implements AuditService
{
return auditComponent.getAuditMinMaxByApp(applicationName, extremes);
}
/**
* {@inheritDoc}
*/
@Override
public int getAuditEntriesCountByApp(String applicationName)
{
return auditComponent.getAuditEntriesCountByApp(applicationName);
}
}

View File

@@ -233,4 +233,15 @@ public interface AuditDAO
* @return a map containing min/max and the associated value
*/
HashMap<String, Long> getAuditMinMaxByApp(long appId, List<String> extremes);
/**
* Issue an audit query to retrieve count of records for a given application.
*
* @param applicationId the database id of the application
* @return a map containing min/max and the associated value
*/
default int getAuditEntriesCountByApp(long applicationId)
{
return -1;
}
}

View File

@@ -65,6 +65,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
private static final String DELETE_ENTRIES_BY_ID = "alfresco.audit.delete_AuditEntriesById";
private static final String INSERT_ENTRY = "alfresco.audit.insert.insert_AuditEntry";
private static final String SELECT_MINMAX_ENTRY_FOR_APP = "alfresco.audit.select_MinMaxAuditEntryId";
private static final String SELECT_COUNT_ENTRIES_FOR_APP = "alfresco.audit.select_CountAuditEntryId";
@SuppressWarnings("unused")
private static final String SELECT_ENTRIES_SIMPLE = "alfresco.audit.select_AuditEntriesSimple";
@@ -223,6 +224,17 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
return result;
}
@Override
public int getAuditEntriesCountByApp(long applicationId)
{
Map<String, Object> params = new HashMap<>();
params.put("auditAppId", applicationId);
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP, params);
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void findAuditEntries(

View File

@@ -241,4 +241,15 @@ public interface AuditService
* @return a map containing min/max and the associated value
*/
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
/**
* Issue an audit query to retrieve min / max audit record id for a given application.
*
* @param applicationName the name of the application
* @return a map containing min/max and the associated value
*/
default int getAuditEntriesCountByApp(String applicationName)
{
return -1;
}
}

View File

@@ -60,6 +60,10 @@
<parameter property="max" jdbcType="VARCHAR" javaType="String"/>
</parameterMap>
<parameterMap id="parameter_AuditAppId" type="map">
<parameter property="auditAppId" jdbcType="BIGINT" javaType="Long"/>
</parameterMap>
<!-- -->
<!-- SQL Snippets -->
<!-- -->
@@ -277,6 +281,16 @@
<include refid="select_AuditEntriesOrderBySnippet"/>
</sql>
<!-- Get the count of audit entries for application -->
<select id="select_CountAuditEntryId" parameterMap="parameter_AuditAppId" resultType="int">
select
COUNT(id)
from
alf_audit_entry
where
alf_audit_entry.audit_app_id = #{auditAppId}
</select>
<!-- Get the maximum/minimum audit entry id for application -->
<select id="select_MinMaxAuditEntryId" parameterMap="parameter_IdMinMaxMap" resultMap="result_minMaxMap">
select