Commit 0d4acb92 authored by LAVENIER's avatar LAVENIER
Browse files

[fix] Fix lastUpdateDate

parent 4a528015
......@@ -50,6 +50,8 @@ import net.sumaris.core.vo.filter.ReferentialFilterVO;
import net.sumaris.core.vo.referential.IReferentialVO;
import net.sumaris.core.vo.referential.ReferentialTypeVO;
import net.sumaris.core.vo.referential.ReferentialVO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.i18n.I18n;
......@@ -467,11 +469,12 @@ public class ReferentialDaoImpl
criteriaQuery.orderBy(builder.desc(root.get(IReferentialEntity.Fields.UPDATE_DATE)));
try {
return getEntityManager().createQuery(criteriaQuery)
return IterableUtils.first(getEntityManager().createQuery(criteriaQuery)
.setMaxResults(1)
.getSingleResult();
.getResultList() // DO NOT use getSingleResult, because table can be null
);
}
catch (NoResultException e) {
catch (Exception e) {
// Table is empty: return null
return null;
}
......
......@@ -46,7 +46,8 @@ import java.util.Date;
@Data
@FieldNameConstants
@Entity
@Table(name = "\"grouping\"",
// FIXME: rename with quote ? BUT query on this table will failed ! (e.g. lastUpdateDate)
@Table(name = "grouping",
uniqueConstraints = @UniqueConstraint(name="grouping_unique_c", columnNames = {"label", "grouping_level_fk"}))
public class Grouping implements IItemReferentialEntity,
IWithValidityStatusEntity<Integer, ValidityStatus> {
......
......@@ -55,6 +55,8 @@ import net.sumaris.server.service.technical.ChangesPublisherService;
import net.sumaris.server.service.technical.TrashService;
import org.apache.commons.collections4.CollectionUtils;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Service;
......@@ -68,6 +70,8 @@ import java.util.Set;
@Service
@Transactional
public class DataGraphQLService {
/* Logger */
private static final Logger log = LoggerFactory.getLogger(DataGraphQLService.class);
@Autowired
private SumarisServerConfiguration config;
......@@ -304,11 +308,32 @@ public class DataGraphQLService {
return result;
}
/**
* @deprecated
*/
@GraphQLMutation(name = "saveTrip", description = "Create or update a trip",
deprecationReason = "Please use saveTrip(TripVO, TripSaveOptions)")
@IsUser
@Deprecated
public TripVO saveTrip(@GraphQLArgument(name = "trip") TripVO trip,
@GraphQLArgument(name = "withOperation", defaultValue = "false") Boolean withOperation,
@GraphQLEnvironment() Set<String> fields) {
// Warn in log
logDeprecatedUse("saveTrip(TripVO, withOperation)", "1.5.0");
return saveTrip(trip, TripSaveOptions.builder()
.withOperation(withOperation)
.build(),
fields);
}
@GraphQLMutation(name = "saveTrip", description = "Create or update a trip")
@IsUser
public TripVO saveTrip(@GraphQLArgument(name = "trip") TripVO trip,
@GraphQLArgument(name = "saveOptions") TripSaveOptions saveOptions,
@GraphQLEnvironment() Set<String> fields) {
final TripVO result = tripService.save(trip, saveOptions);
// Add additional properties if needed
......@@ -317,6 +342,26 @@ public class DataGraphQLService {
return result;
}
/**
* @deprecated
*/
@GraphQLMutation(name = "saveTrips", description = "Create or update many trips",
deprecationReason = "Please use saveTrips(TripVO, TripSaveOptions)")
@IsUser
@Deprecated
public List<TripVO> saveTrips(@GraphQLArgument(name = "trips") List<TripVO> trips,
@GraphQLArgument(name = "withOperation", defaultValue = "false") Boolean withOperation,
@GraphQLEnvironment() Set<String> fields) {
// Warn in log
logDeprecatedUse("saveTrips(TripVO, withOperation)", "1.5.0");
return saveTrips(trips, TripSaveOptions.builder()
.withOperation(withOperation)
.build(),
fields);
}
@GraphQLMutation(name = "saveTrips", description = "Create or update many trips")
@IsUser
public List<TripVO> saveTrips(@GraphQLArgument(name = "trips") List<TripVO> trips,
......@@ -1286,4 +1331,10 @@ public class DataGraphQLService {
protected void checkIsAdmin(String message) {
if (!authService.isAdmin()) throw new AccessDeniedException(message != null ? message : "Forbidden");
}
protected void logDeprecatedUse(String functionName, String appVersion) {
Integer userId = authService.getAuthenticatedUser().map(PersonVO::getId).orElse(null);
log.warn(String.format("User {id: %s} used service {%s} that is deprecated since {appVersion: %s}.", userId, functionName, appVersion));
}
}
......@@ -42,6 +42,7 @@ import net.sumaris.core.vo.referential.TaxonNameVO;
import net.sumaris.server.http.security.IsAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
......@@ -66,7 +67,7 @@ public class ReferentialGraphQLService {
/* -- Referential queries -- */
@GraphQLQuery(name = "lastUpdateDate", description = "Get last update date of all referential")
@Transactional(readOnly = true)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public Date getLastUpdateDate() {
return referentialService.getLastUpdateDate();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment