use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.
the class JPAConnInstanceHistoryConfDAO method delete.
@Override
public void delete(final String key) {
ConnInstanceHistoryConf conf = find(key);
if (conf == null) {
return;
}
entityManager().remove(conf);
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.
the class ConnectorHistoryLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_HISTORY_DELETE + "')")
public void delete(final String key) {
ConnInstanceHistoryConf connInstanceHistoryConf = connInstanceHistoryConfDAO.find(key);
if (connInstanceHistoryConf == null) {
throw new NotFoundException("Connector History Conf '" + key + "'");
}
connInstanceHistoryConfDAO.delete(key);
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.
the class ConnInstanceHistoryConfTest method createDelete.
@Test
public void createDelete() {
ConnInstance ldapConnector = connInstanceDAO.find("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
assertNotNull(ldapConnector);
ConnInstanceHistoryConf ldapHistory = entityFactory.newEntity(ConnInstanceHistoryConf.class);
ldapHistory.setCreation(new Date());
ldapHistory.setCreator("me");
ldapHistory.setEntity(ldapConnector);
ldapHistory.setConf(new ConnInstanceTO());
ldapHistory = connInstanceHistoryConfDAO.save(ldapHistory);
assertNotNull(ldapHistory.getKey());
connInstanceHistoryConfDAO.flush();
List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(ldapConnector);
assertEquals(1, history.size());
assertEquals(ldapHistory, history.get(0));
connInstanceHistoryConfDAO.delete(ldapHistory.getKey());
connInstanceHistoryConfDAO.flush();
assertNull(connInstanceHistoryConfDAO.find(ldapHistory.getKey()));
assertTrue(connInstanceHistoryConfDAO.findByEntity(ldapConnector).isEmpty());
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.
the class ConnInstanceDataBinderImpl method update.
@Override
public ConnInstance update(final ConnInstanceTO connInstanceTO) {
ConnInstance connInstance = connInstanceDAO.authFind(connInstanceTO.getKey());
if (connInstance == null) {
throw new NotFoundException("Connector '" + connInstanceTO.getKey() + "'");
}
ConnInstanceTO current = getConnInstanceTO(connInstance);
if (!current.equals(connInstanceTO)) {
// 1. save the current configuration, before update
ConnInstanceHistoryConf connInstanceHistoryConf = entityFactory.newEntity(ConnInstanceHistoryConf.class);
connInstanceHistoryConf.setCreator(AuthContextUtils.getUsername());
connInstanceHistoryConf.setCreation(new Date());
connInstanceHistoryConf.setEntity(connInstance);
connInstanceHistoryConf.setConf(current);
connInstanceHistoryConfDAO.save(connInstanceHistoryConf);
// 2. ensure the maximum history size is not exceeded
List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(connInstance);
long maxHistorySize = confDAO.find("connector.conf.history.size", 10L);
if (maxHistorySize < history.size()) {
// always remove the last item since history was obtained by a query with ORDER BY creation DESC
for (int i = 0; i < history.size() - maxHistorySize; i++) {
connInstanceHistoryConfDAO.delete(history.get(history.size() - 1).getKey());
}
}
}
// 3. actual update
connInstance.getCapabilities().clear();
connInstance.getCapabilities().addAll(connInstanceTO.getCapabilities());
if (connInstanceTO.getAdminRealm() != null) {
Realm realm = realmDAO.findByFullPath(connInstanceTO.getAdminRealm());
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm());
throw sce;
}
connInstance.setAdminRealm(realm);
}
if (connInstanceTO.getLocation() != null) {
connInstance.setLocation(connInstanceTO.getLocation());
}
if (connInstanceTO.getBundleName() != null) {
connInstance.setBundleName(connInstanceTO.getBundleName());
}
if (connInstanceTO.getVersion() != null) {
connInstance.setVersion(connInstanceTO.getVersion());
}
if (connInstanceTO.getConnectorName() != null) {
connInstance.setConnectorName(connInstanceTO.getConnectorName());
}
if (connInstanceTO.getConf() != null && !connInstanceTO.getConf().isEmpty()) {
connInstance.setConf(connInstanceTO.getConf());
}
if (connInstanceTO.getDisplayName() != null) {
connInstance.setDisplayName(connInstanceTO.getDisplayName());
}
if (connInstanceTO.getConnRequestTimeout() != null) {
connInstance.setConnRequestTimeout(connInstanceTO.getConnRequestTimeout());
}
if (connInstanceTO.getPoolConf() == null) {
connInstance.setPoolConf(null);
} else {
connInstance.setPoolConf(ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
}
try {
connInstance = connInstanceDAO.save(connInstance);
} catch (Exception e) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
sce.getElements().add(e.getMessage());
throw sce;
}
return connInstance;
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.
the class ConnectorHistoryLogic method restore.
@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_HISTORY_RESTORE + "')")
public void restore(final String key) {
ConnInstanceHistoryConf connInstanceHistoryConf = connInstanceHistoryConfDAO.find(key);
if (connInstanceHistoryConf == null) {
throw new NotFoundException("Connector History Conf '" + key + "'");
}
binder.update(connInstanceHistoryConf.getConf());
}
Aggregations