reset ReadCount
This commit is contained in:
parent
216d9cf53c
commit
eefbaf0607
|
@ -0,0 +1,40 @@
|
|||
package eu.dnetlib.data.mdstore.manager.controller;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
public abstract class AbstractDnetController {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public @ResponseBody ErrorMessage handleException(final Exception e) {
|
||||
return new ErrorMessage(e);
|
||||
}
|
||||
|
||||
public class ErrorMessage {
|
||||
|
||||
private final String message;
|
||||
private final String stacktrace;
|
||||
|
||||
public ErrorMessage(final Exception e) {
|
||||
this(e.getMessage(), ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
|
||||
public ErrorMessage(final String message, final String stacktrace) {
|
||||
this.message = message;
|
||||
this.stacktrace = stacktrace;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public String getStacktrace() {
|
||||
return this.stacktrace;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ import io.swagger.annotations.ApiParam;
|
|||
@Api(tags = {
|
||||
"Metadata Stores"
|
||||
})
|
||||
public class MDStoreController {
|
||||
public class MDStoreController extends AbstractDnetController {
|
||||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
|
@ -121,6 +121,13 @@ public class MDStoreController {
|
|||
return databaseUtils.endReading(versionId);
|
||||
}
|
||||
|
||||
@ApiOperation("Reset the read count of a mdstore version")
|
||||
@GetMapping("/version/{versionId}/resetReading")
|
||||
public MDStoreVersion resetReading(@ApiParam("the id of the version") @PathVariable final String versionId)
|
||||
throws MDStoreManagerException {
|
||||
return databaseUtils.resetReading(versionId);
|
||||
}
|
||||
|
||||
@ApiOperation("Delete multiple mdstore versions")
|
||||
@PostMapping("/versions/deleteList")
|
||||
public StatusResponse deleteVersions(@ApiParam("the list of ids of the versions that have to be deleted") @RequestBody final String[] versions,
|
||||
|
|
|
@ -6,9 +6,11 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import eu.dnetlib.data.mdstore.manager.common.model.MDStore;
|
||||
import eu.dnetlib.data.mdstore.manager.common.model.MDStoreCurrentVersion;
|
||||
|
@ -20,7 +22,7 @@ import eu.dnetlib.data.mdstore.manager.repository.MDStoreRepository;
|
|||
import eu.dnetlib.data.mdstore.manager.repository.MDStoreVersionRepository;
|
||||
import eu.dnetlib.data.mdstore.manager.repository.MDStoreWithInfoRepository;
|
||||
|
||||
@Component
|
||||
@Service
|
||||
public class DatabaseUtils {
|
||||
|
||||
@Autowired
|
||||
|
@ -34,6 +36,8 @@ public class DatabaseUtils {
|
|||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DatabaseUtils.class);
|
||||
|
||||
public Iterable<MDStoreWithInfo> listMdStores() {
|
||||
return mdstoreWithInfoRepository.findAll();
|
||||
}
|
||||
|
@ -80,14 +84,19 @@ public class DatabaseUtils {
|
|||
|
||||
@Transactional
|
||||
public void deleteMdStore(final String mdId) throws MDStoreManagerException {
|
||||
if (!mdstoreRepository.existsById(mdId)) { throw new MDStoreManagerException("On delete MDStore not found " + "[" + mdId + "]"); }
|
||||
if (!mdstoreRepository.existsById(mdId)) {
|
||||
log.error("MDStore not found: " + mdId);
|
||||
throw new MDStoreManagerException("MDStore not found: " + mdId);
|
||||
}
|
||||
|
||||
if (mdstoreVersionRepository.countByMdstoreAndReadCountGreaterThan(mdId, 0) > 0) {
|
||||
throw new MDStoreManagerException("Read transactions found on mdstore : " + mdId);
|
||||
log.error("Read transactions found on mdstore: " + mdId);
|
||||
throw new MDStoreManagerException("Read transactions found on mdstore: " + mdId);
|
||||
}
|
||||
|
||||
if (mdstoreVersionRepository.countByMdstoreAndWriting(mdId, true) > 0) {
|
||||
throw new MDStoreManagerException("Write transactions found on mdstore : " + mdId);
|
||||
log.error("Write transactions found on mdstore: " + mdId);
|
||||
throw new MDStoreManagerException("Write transactions found on mdstore: " + mdId);
|
||||
}
|
||||
|
||||
mdstoreCurrentVersionRepository.deleteById(mdId);
|
||||
|
@ -109,7 +118,14 @@ public class DatabaseUtils {
|
|||
@Transactional
|
||||
public MDStoreVersion endReading(final String versionId) throws MDStoreManagerException {
|
||||
final MDStoreVersion v = mdstoreVersionRepository.findById(versionId).orElseThrow(() -> new MDStoreManagerException("Version not found"));
|
||||
v.setReadCount(v.getReadCount() - 1);
|
||||
v.setReadCount(Math.max(0, v.getReadCount() - 1));
|
||||
return v;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public MDStoreVersion resetReading(final String versionId) throws MDStoreManagerException {
|
||||
final MDStoreVersion v = mdstoreVersionRepository.findById(versionId).orElseThrow(() -> new MDStoreManagerException("Version not found"));
|
||||
v.setReadCount(0);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
@ -144,11 +144,14 @@
|
|||
<tbody>
|
||||
<tr ng-repeat="v in versions">
|
||||
<td ng-class="{'text-success': v.current}"><span class="glyphicon glyphicon-pencil" ng-if="v.writing" title="writing..."></span> {{v.id}}</td>
|
||||
<td class="text-center">{{v.readCount}}</td>
|
||||
<td class="text-center">
|
||||
{{v.readCount}}
|
||||
<button class="btn btn-xs btn-warning" ng-click="resetReading(v.id)" ng-disabled="v.readCount == 0">reset</button>
|
||||
</td>
|
||||
<td class="text-center" title="{{v.lastUpdate}}">{{v.lastUpdate | date:"MMM dd, yyyy 'at' HH:mm"}}</td>
|
||||
<td class="text-right">{{v.size}}</td>
|
||||
<td class="text-right">
|
||||
<button class="btn btn-sm btn-primary" ng-if="v.writing" ng-click="commitVersion(v.id)">commit</button>
|
||||
<button class="btn btn-sm btn-primary" ng-show="v.writing" ng-click="commitVersion(v.id)">commit</button>
|
||||
<button class="btn btn-sm btn-danger" ng-disabled="v.current" ng-click="deleteVersion(v.id, forceVersionDelete)">delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -11,8 +11,8 @@ app.controller('mdstoreManagerController', function($scope, $http) {
|
|||
$scope.reload = function() {
|
||||
$http.get('/mdstores/?' + $.now()).success(function(data) {
|
||||
$scope.mdstores = data;
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -23,8 +23,8 @@ app.controller('mdstoreManagerController', function($scope, $http) {
|
|||
}
|
||||
$http.get(url).success(function(data) {
|
||||
$scope.reload();
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -32,8 +32,8 @@ app.controller('mdstoreManagerController', function($scope, $http) {
|
|||
if (confirm("Are you sure ?")) {
|
||||
$http.delete('/mdstores/mdstore/' + mdId).success(function(data) {
|
||||
$scope.reload();
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -43,8 +43,8 @@ app.controller('mdstoreManagerController', function($scope, $http) {
|
|||
$http.get('/mdstores/mdstore/' + mdId + '/newVersion?' + $.now()).success(function(data) {
|
||||
$scope.reload();
|
||||
$scope.listVersions(mdId, currentVersion);
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -55,12 +55,21 @@ app.controller('mdstoreManagerController', function($scope, $http) {
|
|||
$scope.reload();
|
||||
$scope.openCurrentVersion = versionId;
|
||||
$scope.refreshVersions();
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.resetReading = function(versionId) {
|
||||
$http.get("/mdstores/version/" + versionId + "/resetReading" + '?' + $.now()).success(function(data) {
|
||||
$scope.reload();
|
||||
$scope.refreshVersions();
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.listVersions = function(mdId, current) {
|
||||
$scope.openMdstore = mdId;
|
||||
$scope.openCurrentVersion = current;
|
||||
|
@ -74,8 +83,8 @@ app.controller('mdstoreManagerController', function($scope, $http) {
|
|||
value.current = (value.id == $scope.openCurrentVersion);
|
||||
});
|
||||
$scope.versions = data;
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -87,8 +96,8 @@ app.controller('mdstoreManagerController', function($scope, $http) {
|
|||
$http.delete(url).success(function(data) {
|
||||
$scope.reload();
|
||||
$scope.refreshVersions();
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
}).error(function(err) {
|
||||
alert('ERROR: ' + err.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue