List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:com.redhat.lightblue.crud.ldap.LdapCRUDController.java
@Override public CRUDInsertionResponse insert(CRUDOperationContext ctx, Projection projection) { CRUDInsertionResponse response = new CRUDInsertionResponse(); response.setNumInserted(0);/* www .j a v a 2 s. c om*/ List<DocCtx> documents = ctx.getDocumentsWithoutErrors(); if (documents == null || documents.isEmpty()) { return response; } EntityMetadata md = ctx.getEntityMetadata(ctx.getEntityName()); LdapDataStore store = LdapCrudUtil.getLdapDataStore(md); LdapFieldNameTranslator fieldNameTranslator = LdapCrudUtil.getLdapFieldNameTranslator(md); FieldAccessRoleEvaluator roles = new FieldAccessRoleEvaluator(md, ctx.getCallerRoles()); EntryBuilder entryBuilder = new EntryBuilder(md, fieldNameTranslator); //Create Entry instances for each document. List<com.unboundid.ldap.sdk.Entry> entries = new ArrayList<com.unboundid.ldap.sdk.Entry>(); Map<DocCtx, String> documentToDnMap = new HashMap<DocCtx, String>(); boolean hasError = false; for (DocCtx document : documents) { List<Path> paths = roles.getInaccessibleFields_Insert(document); if ((paths != null) && !paths.isEmpty()) { for (Path path : paths) { document.addError( Error.get("insert", CrudConstants.ERR_NO_FIELD_INSERT_ACCESS, path.toString())); continue; } } Path uniqueFieldPath = fieldNameTranslator.translateAttributeName(store.getUniqueAttribute()); JsonNode uniqueNode = document.get(uniqueFieldPath); if (uniqueNode == null) { throw Error.get(MetadataConstants.ERR_PARSE_MISSING_ELEMENT, store.getUniqueAttribute()); } String dn = LdapCrudUtil.createDN(store, uniqueNode.asText()); documentToDnMap.put(document, dn); try { entries.add(entryBuilder.build(dn, document)); } catch (Exception e) { document.addError(Error.get(e)); hasError = true; } } if (hasError) { return response; } //Persist each Entry. LDAPConnection connection = getNewLdapConnection(store); for (com.unboundid.ldap.sdk.Entry entry : entries) { InsertCommand command = new InsertCommand(connection, entry); LDAPResult result = command.execute(); if (result.getResultCode() != ResultCode.SUCCESS) { //TODO: Do something to indicate unsuccessful status continue; } response.setNumInserted(response.getNumInserted() + 1); } projectChanges(projection, ctx, documentToDnMap); return response; }