use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class CleanUpClientTest method cleanUpClient.
@Test
@Parameters(value = "usedClients")
public void cleanUpClient(String usedClients) {
Assert.assertNotNull(usedClients);
List<String> usedClientsList = Arrays.asList(StringHelper.split(usedClients, ",", true, false));
output("Used clients: " + usedClientsList);
int clientsResultSetSize = 50;
int countResults = 0;
int countRemoved = 0;
boolean existsMoreClients = true;
while (existsMoreClients && countResults < 10000) {
List<Client> clients = clientService.getAllClients(new String[] { "inum" }, clientsResultSetSize);
existsMoreClients = clients.size() == clientsResultSetSize;
countResults += clients.size();
Assert.assertNotNull(clients);
output("Found clients: " + clients.size());
output("Total clients: " + countResults);
for (Client client : clients) {
String clientId = client.getClientId();
if (!usedClientsList.contains(clientId)) {
try {
clientService.remove(client);
} catch (EntryPersistenceException ex) {
output("Failed to remove client: " + ex.getMessage());
}
countRemoved++;
}
}
}
output("Removed clients: " + countRemoved);
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class JansPersistenceService method getExpiredObject.
public ExpiredObject getExpiredObject(String key) {
try {
ExpiredObject expiredObject = (ExpiredObject) this.persistenceEntryManager.find(getDnForExpiredObj(key), ExpiredObject.class, null);
if (expiredObject != null) {
expiredObject.setType(ExpiredObjectType.fromValue(expiredObject.getTypeString()));
LOG.debug("Found ExpiredObject id: {} , ExpiredObject : {} ", key, expiredObject);
return expiredObject;
}
LOG.error("Failed to fetch ExpiredObject by id: {} ", key);
return null;
} catch (Exception e) {
if (((e instanceof EntryPersistenceException)) && (e.getMessage().contains("Failed to find entry"))) {
LOG.warn("Failed to fetch ExpiredObject by id: {}. {} ", key, e.getMessage());
return null;
}
LOG.error("Failed to fetch ExpiredObject by id: {} ", key, e);
}
return null;
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class JansPersistenceService method getRps.
public Set<Rp> getRps() {
try {
List<RpObject> rpObjects = this.persistenceEntryManager.findEntries(String.format("%s,%s", new Object[] { getRpOu(), getClientApiDn() }), RpObject.class, null);
Set<Rp> result = new HashSet();
for (RpObject ele : rpObjects) {
Rp rp = MigrationService.parseRp(ele.getData());
if (rp != null) {
result.add(rp);
} else {
LOG.error("Failed to parse rp, id: {}, dn: {} ", ele.getId(), ele.getDn());
}
}
return result;
} catch (Exception e) {
if (((e instanceof EntryPersistenceException)) && (e.getMessage().contains("Failed to find entries"))) {
LOG.warn("Failed to fetch RpObjects. {} ", e.getMessage());
return null;
}
LOG.error("Failed to fetch rps. Error: {} ", e.getMessage(), e);
}
return null;
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class CouchbaseEntryManager method findEntriesImpl.
protected <T> PagedResult<JsonObject> findEntriesImpl(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, BatchOperation<T> batchOperation, SearchReturnDataType returnDataType, int start, int count, int chunkSize) {
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
String[] currentLdapReturnAttributes = ldapReturnAttributes;
if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
}
Filter searchFilter;
if (objectClasses.length > 0) {
LOG.trace("Filter: {}", filter);
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Find entries
LOG.trace("-------------------------------------------------------");
LOG.trace("Filter: {}", filter);
LOG.trace("objectClasses count: {} ", objectClasses.length);
LOG.trace("objectClasses: {}", ArrayHelper.toString(objectClasses));
LOG.trace("Search filter: {}", searchFilter);
// Prepare default sort
Sort[] defaultSort = getDefaultSort(entryClass);
if (StringHelper.isNotEmpty(sortBy)) {
Sort requestedSort = buildSort(sortBy, sortOrder);
if (ArrayHelper.isEmpty(defaultSort)) {
defaultSort = new Sort[] { requestedSort };
} else {
defaultSort = ArrayHelper.arrayMerge(new Sort[] { requestedSort }, defaultSort);
}
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ParsedKey keyWithInum = toCouchbaseKey(baseDN);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
}
PagedResult<JsonObject> searchResult = null;
try {
CouchbaseBatchOperationWraper<T> batchOperationWraper = null;
if (batchOperation != null) {
batchOperationWraper = new CouchbaseBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
}
searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), scope, currentLdapReturnAttributes, defaultSort, batchOperationWraper, returnDataType, start, count, chunkSize);
if (searchResult == null) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression));
}
return searchResult;
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression), ex);
}
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class CouchbaseUpateMissingEntrySample method main.
public static void main(String[] args) {
// Prepare sample connection details
CouchbaseEntryManagerSample sqlSampleEntryManager = new CouchbaseEntryManagerSample();
// Create SQL entry manager
CouchbaseEntryManager sqlEntryManager = sqlSampleEntryManager.createCouchbaseEntryManager();
String sessionId = UUID.randomUUID().toString();
final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
final SimpleSessionState simpleSessionState = new SimpleSessionState();
simpleSessionState.setDn(sessionDn);
simpleSessionState.setId(sessionId);
simpleSessionState.setLastUsedAt(new Date());
try {
sqlEntryManager.merge(simpleSessionState);
System.out.println("Updated");
} catch (EntryPersistenceException ex) {
LOG.info("Failed to update, root case exception: {}", ex.getCause().getClass(), ex);
}
}
Aggregations