Search in sources :

Example 11 with Value

use of com.google.firestore.v1beta1.Value in project grpc-gcp-java by GoogleCloudPlatform.

the class DataStoreChecksumClient method simpleLookup.

private static void simpleLookup(DatastoreBlockingStub stub, String projectId) {
    PathElement pathElement = PathElement.newBuilder().setKind("Person").setName("weiranf").build();
    Key key = Key.newBuilder().addPath(pathElement).build();
    LookupRequest lookupRequest = LookupRequest.newBuilder().setProjectId(projectId).addKeys(key).build();
    LookupResponse lookupResponse = stub.lookup(lookupRequest);
    if (lookupResponse.getFoundCount() > 0) {
        System.out.println("ENTITY FOUND:");
        Entity entity = lookupResponse.getFound(0).getEntity();
        Map<String, Value> map = entity.getPropertiesMap();
        for (Map.Entry<String, Value> entry : map.entrySet()) {
            System.out.printf("%s => %s\n", entry.getKey(), entry.getValue().getStringValue());
        }
    } else {
        System.out.println("NO ENTITY FOUND!");
    }
}
Also used : Entity(com.google.datastore.v1.Entity) PathElement(com.google.datastore.v1.Key.PathElement) Value(com.google.datastore.v1.Value) LookupResponse(com.google.datastore.v1.LookupResponse) Map(java.util.Map) Key(com.google.datastore.v1.Key) LookupRequest(com.google.datastore.v1.LookupRequest)

Example 12 with Value

use of com.google.firestore.v1beta1.Value in project grpc-gcp-java by GoogleCloudPlatform.

the class MakeFieldsMap method makeFieldsMap.

public HashMap<String, Value> makeFieldsMap() {
    String fieldName = "initial";
    String fieldValue = "initial";
    Scanner sc = new Scanner(System.in);
    HashMap<String, Value> inputFields = new HashMap<>();
    while (!fieldName.matches("DONE")) {
        System.out.print("Field Name (Enter DONE to quit): ");
        fieldName = sc.next();
        if (!fieldName.matches("DONE")) {
            System.out.print("Field Value: ");
            fieldValue = sc.next();
            Value fsValue = Value.newBuilder().setStringValue(fieldValue).build();
            inputFields.put(fieldName, fsValue);
        }
    }
    return inputFields;
}
Also used : Scanner(java.util.Scanner) HashMap(java.util.HashMap) Value(com.google.firestore.v1beta1.Value)

Example 13 with Value

use of com.google.firestore.v1beta1.Value in project meveo by meveo-org.

the class Neo4jService method deleteEntity.

public void deleteEntity(String neo4jConfiguration, String cetCode, Map<String, Object> values) throws BusinessException {
    /* Get entity template */
    final CustomEntityTemplate customEntityTemplate = customFieldsCache.getCustomEntityTemplate(cetCode);
    /* Extract unique fields values for node */
    final Map<String, Object> uniqueFields = getNodeKeys(customEntityTemplate.getAppliesTo(), values);
    /* No unique fields has been found */
    if (uniqueFields.isEmpty()) {
        throw new BusinessException("At least one unique field must be provided for cet to delete");
    }
    final String uniqueFieldStatement = neo4jDao.getFieldsString(uniqueFields.keySet());
    /* Map the variables declared in the statement */
    Map<String, Object> valuesMap = new HashMap<>();
    valuesMap.put("cetCode", cetCode);
    valuesMap.put("uniqueFields", uniqueFieldStatement);
    String deleteStatement = getStatement(new StrSubstitutor(valuesMap), Neo4JRequests.deleteCet);
    final Transaction transaction = crossStorageTransaction.getNeo4jTransaction(neo4jConfiguration);
    InternalNode internalNode = null;
    try {
        /* Delete the node and all its associated relationships and fire node deletion event */
        // Execute query
        final StatementResult result = transaction.run(deleteStatement, values);
        for (Record record : result.list()) {
            // Fire deletion event
            // Parse properties
            final Map<String, Value> properties = record.get("properties").asMap(e -> e);
            // Parse labels
            final List<String> labels = record.get("labels").asList(Value::asString);
            // Parse id
            final long id = record.get("id").asLong();
            // Create Node object
            internalNode = new InternalNode(id, labels, properties);
        }
        transaction.success();
    } catch (Exception e) {
        log.error("Cannot delete node with code {} and values {}", cetCode, values, e);
        transaction.failure();
        throw new BusinessException(e);
    }
    if (internalNode != null) {
        // Fire notification
        nodeRemovedEvent.fire(new Neo4jEntity(internalNode, neo4jConfiguration));
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ELException(org.meveo.elresolver.ELException) PatternSyntaxException(java.util.regex.PatternSyntaxException) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) BusinessException(org.meveo.admin.exception.BusinessException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) RemoteAuthenticationException(org.meveo.export.RemoteAuthenticationException) InvalidCustomFieldException(org.meveo.exceptions.InvalidCustomFieldException) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) BusinessException(org.meveo.admin.exception.BusinessException) CrossStorageTransaction(org.meveo.persistence.CrossStorageTransaction) Transaction(org.neo4j.driver.v1.Transaction) CustomEntityTemplate(org.meveo.model.customEntities.CustomEntityTemplate) CustomFieldValue(org.meveo.model.crm.custom.CustomFieldValue) Value(org.neo4j.driver.v1.Value) Neo4jEntity(org.meveo.persistence.neo4j.graph.Neo4jEntity) Record(org.neo4j.driver.v1.Record) InternalNode(org.neo4j.driver.internal.InternalNode)

Example 14 with Value

use of com.google.firestore.v1beta1.Value in project meveo by meveo-org.

the class Neo4jService method addSourceNodeUniqueCrt.

/**
 * Persist a source node of an unique relationship.
 * If a relationship that targets the target node exists, then we merge the fields of the start in parameter to
 * the fields of the source node of the relationship.
 * If such a relation does not exists, we create the source node with it fields.
 *
 * @param neo4JConfiguration Neo4J coordinates
 * @param crtCode            Code of the unique relation
 * @param startNodeValues    Values to assign to the start node
 * @param endNodeValues      Filters on the target node values
 */
@JpaAmpNewTx
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public PersistenceActionResult addSourceNodeUniqueCrt(String neo4JConfiguration, String crtCode, Map<String, Object> startNodeValues, Map<String, Object> endNodeValues) throws BusinessException, ELException {
    // Get relationship template
    final CustomRelationshipTemplate customRelationshipTemplate = customFieldsCache.getCustomRelationshipTemplate(crtCode);
    final CustomEntityTemplate endNode = customRelationshipTemplate.getEndNode();
    // Extract unique fields values for the start node
    Map<String, CustomFieldTemplate> endNodeCfts = customFieldTemplateService.findByAppliesTo(endNode.getAppliesTo());
    Map<String, CustomFieldTemplate> startNodeCfts = customFieldTemplateService.findByAppliesTo(customRelationshipTemplate.getStartNode().getAppliesTo());
    final Map<String, Object> endNodeUniqueFields = new HashMap<>();
    Map<String, Object> endNodeConvertedValues = validateAndConvertCustomFields(endNodeCfts, endNodeValues, endNodeUniqueFields, true);
    Map<String, Object> startNodeConvertedValues = validateAndConvertCustomFields(startNodeCfts, startNodeValues, null, true);
    // Map the variables declared in the statement
    Map<String, Object> valuesMap = new HashMap<>();
    final String cetCode = customRelationshipTemplate.getStartNode().getCode();
    valuesMap.put("cetCode", cetCode);
    valuesMap.put("crtCode", crtCode);
    valuesMap.put("endCetcode", customRelationshipTemplate.getEndNode().getCode());
    // Prepare the key maps for unique fields and start node fields
    final String uniqueFieldStatements = neo4jDao.getFieldsString(endNodeConvertedValues.keySet());
    final String startNodeValuesStatements = neo4jDao.getFieldsString(startNodeConvertedValues.keySet());
    // No unique fields has been found
    if (endNodeUniqueFields.isEmpty()) {
        // If no unique fields are provided / defined, retrieve the meveo_uuid of the target node using unicity rules
        Set<String> ids = endNode.getNeo4JStorageConfiguration().getUniqueConstraints().stream().filter(uniqueConstraint -> uniqueConstraint.getTrustScore() == 100).filter(uniqueConstraint -> isApplicableConstraint(endNodeValues, uniqueConstraint)).sorted(Neo4jService.CONSTRAINT_COMPARATOR).map(uniqueConstraint -> neo4jDao.executeUniqueConstraint(neo4JConfiguration, uniqueConstraint, endNodeValues, endNode.getCode())).findFirst().orElse(Set.of());
        if (ids.isEmpty()) {
            log.error("At least one unique field must be provided for target entity [code = {}, fields = {}]. " + "Unique fields are : {}", customRelationshipTemplate.getEndNode().getCode(), endNodeValues, endNodeUniqueFields);
            throw new BusinessException("Unique field must be provided");
        }
        if (ids.size() > 1) {
            throw new BusinessException(String.format("Multiple targets for unique relationship %s : %s.", crtCode, ids));
        }
        String id = ids.iterator().next();
        endNodeValues.put("meveo_uuid", id);
        endNodeUniqueFields.put("meveo_uuid", id);
    }
    // Assign the keys names
    valuesMap.put(FIELD_KEYS, uniqueFieldStatements);
    valuesMap.put(FIELDS, startNodeValuesStatements);
    // Create the substitutor
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    // Values of the keys defined in valuesMap
    Map<String, Object> parametersValues = new HashMap<>();
    parametersValues.putAll(startNodeConvertedValues);
    parametersValues.putAll(endNodeConvertedValues);
    final Transaction transaction = crossStorageTransaction.getNeo4jTransaction(neo4JConfiguration);
    // Try to find the id of the source node
    String findStartNodeStatement = getStatement(sub, Neo4JRequests.findStartNodeId);
    final StatementResult run = transaction.run(findStartNodeStatement, parametersValues);
    Neo4jEntity startNode = null;
    try {
        try {
            /* Update the source node with the found id */
            // Alias to use in queries
            final String startNodeAlias = "startNode";
            // Retrieve ID of the node
            final Record idRecord = run.single();
            final Value id = idRecord.get(0);
            parametersValues.put(NODE_ID, id);
            // Create statement
            CustomEntityTemplate startCet = customRelationshipTemplate.getStartNode();
            List<String> additionalLabels = getAdditionalLabels(startCet);
            final Map<String, Object> updatableValues = valuesMap.entrySet().stream().filter(s -> startNodeCfts.get(s.getKey()).isAllowEdit()).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
            StringBuffer statement = neo4jDao.appendAdditionalLabels(Neo4JRequests.updateNodeWithId, additionalLabels, startNodeAlias, updatableValues);
            statement = neo4jDao.appendReturnStatement(statement, startNodeAlias, valuesMap);
            String updateStatement = getStatement(sub, statement);
            // Execute query
            final StatementResult result = transaction.run(updateStatement, parametersValues);
            // Fire node update event
            startNode = new Neo4jEntity(result.single().get(startNodeAlias).asNode(), neo4JConfiguration);
        } catch (NoSuchRecordException e) {
            /* Create the source node */
            addCetNode(neo4JConfiguration, customRelationshipTemplate.getStartNode(), startNodeValues, null);
        }
        transaction.success();
    } catch (Exception e) {
        transaction.failure();
        log.error("Transaction for persisting entity with code {} and fields {} was rolled back", cetCode, startNodeValues, e);
        throw new BusinessException(e);
    }
    if (startNode != null) {
        nodeUpdatedEvent.fire(startNode);
        return new PersistenceActionResult(startNode.get("meveo_uuid").asString());
    } else {
        return null;
    }
}
Also used : CustomRelationshipTemplateService(org.meveo.service.custom.CustomRelationshipTemplateService) CrossStorageTransaction(org.meveo.persistence.CrossStorageTransaction) CustomPersistenceService(org.meveo.persistence.CustomPersistenceService) Date(java.util.Date) ELException(org.meveo.elresolver.ELException) LoggerFactory(org.slf4j.LoggerFactory) RepositoryService(org.meveo.service.storage.RepositoryService) StringUtils(org.meveo.commons.utils.StringUtils) ScriptInstanceService(org.meveo.service.script.ScriptInstanceService) CustomEntityTemplateUniqueConstraint(org.meveo.model.crm.CustomEntityTemplateUniqueConstraint) CustomRelationshipTemplate(org.meveo.model.customEntities.CustomRelationshipTemplate) Future(java.util.concurrent.Future) Repository(org.meveo.model.storage.Repository) Matcher(java.util.regex.Matcher) TransactionAttributeType(javax.ejb.TransactionAttributeType) MeveoJpa(org.meveo.jpa.MeveoJpa) Asynchronous(javax.ejb.Asynchronous) CustomFieldValue(org.meveo.model.crm.custom.CustomFieldValue) Map(java.util.Map) CETUtils(org.meveo.api.CETUtils) AsyncResult(javax.ejb.AsyncResult) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) Value(org.neo4j.driver.v1.Value) PatternSyntaxException(java.util.regex.PatternSyntaxException) ApplicationProvider(org.meveo.util.ApplicationProvider) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) CustomEntityInstance(org.meveo.model.customEntities.CustomEntityInstance) Neo4jRelationship(org.meveo.persistence.neo4j.graph.Neo4jRelationship) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Instant(java.time.Instant) Transaction(org.neo4j.driver.v1.Transaction) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) BusinessException(org.meveo.admin.exception.BusinessException) CustomEntityTemplate(org.meveo.model.customEntities.CustomEntityTemplate) Node(org.neo4j.driver.v1.types.Node) List(java.util.List) Response(javax.ws.rs.core.Response) CustomFieldStorageTypeEnum(org.meveo.model.crm.custom.CustomFieldStorageTypeEnum) HttpURLConnection(org.apache.commons.httpclient.util.HttpURLConnection) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) Entry(java.util.Map.Entry) CustomFieldsCacheContainerProvider(org.meveo.cache.CustomFieldsCacheContainerProvider) Optional(java.util.Optional) CustomEntityTemplateUtils(org.meveo.service.custom.CustomEntityTemplateUtils) Pattern(java.util.regex.Pattern) StatementResult(org.neo4j.driver.v1.StatementResult) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) BusinessEntity(org.meveo.model.BusinessEntity) PaginationConfiguration(org.meveo.admin.util.pagination.PaginationConfiguration) RemoteAuthenticationException(org.meveo.export.RemoteAuthenticationException) JpaAmpNewTx(org.meveo.jpa.JpaAmpNewTx) NODE_ID(org.meveo.persistence.neo4j.base.Neo4jDao.NODE_ID) EntityReferenceWrapper(org.meveo.model.crm.EntityReferenceWrapper) BasicAuthentication(org.jboss.resteasy.client.jaxrs.BasicAuthentication) PersistenceActionResult(org.meveo.persistence.PersistenceActionResult) HashMap(java.util.HashMap) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) Updated(org.meveo.event.qualifier.Updated) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Record(org.neo4j.driver.v1.Record) HashSet(java.util.HashSet) Inject(javax.inject.Inject) JacksonUtil(org.meveo.model.persistence.JacksonUtil) Removed(org.meveo.event.qualifier.Removed) Provider(org.meveo.model.crm.Provider) CustomFieldTemplateService(org.meveo.service.crm.impl.CustomFieldTemplateService) MeveoValueExpressionWrapper(org.meveo.service.base.MeveoValueExpressionWrapper) TransactionAttribute(javax.ejb.TransactionAttribute) Neo4jDao(org.meveo.persistence.neo4j.base.Neo4jDao) Event(javax.enterprise.event.Event) InvalidCustomFieldException(org.meveo.exceptions.InvalidCustomFieldException) Logger(org.slf4j.Logger) DBStorageType(org.meveo.model.persistence.DBStorageType) Created(org.meveo.event.qualifier.Created) EntityManagerWrapper(org.meveo.jpa.EntityManagerWrapper) CustomFieldTypeEnum(org.meveo.model.crm.custom.CustomFieldTypeEnum) Neo4jEntity(org.meveo.persistence.neo4j.graph.Neo4jEntity) CustomFieldIndexTypeEnum(org.meveo.model.crm.custom.CustomFieldIndexTypeEnum) InternalNode(org.neo4j.driver.internal.InternalNode) Relationship(org.neo4j.driver.v1.types.Relationship) Comparator(java.util.Comparator) Collections(java.util.Collections) EntityRef(org.meveo.persistence.scheduler.EntityRef) Values(org.neo4j.driver.v1.Values) StatementResult(org.neo4j.driver.v1.StatementResult) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ELException(org.meveo.elresolver.ELException) PatternSyntaxException(java.util.regex.PatternSyntaxException) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) BusinessException(org.meveo.admin.exception.BusinessException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) RemoteAuthenticationException(org.meveo.export.RemoteAuthenticationException) InvalidCustomFieldException(org.meveo.exceptions.InvalidCustomFieldException) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) BusinessException(org.meveo.admin.exception.BusinessException) CrossStorageTransaction(org.meveo.persistence.CrossStorageTransaction) Transaction(org.neo4j.driver.v1.Transaction) CustomEntityTemplate(org.meveo.model.customEntities.CustomEntityTemplate) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) CustomFieldValue(org.meveo.model.crm.custom.CustomFieldValue) Value(org.neo4j.driver.v1.Value) Neo4jEntity(org.meveo.persistence.neo4j.graph.Neo4jEntity) Record(org.neo4j.driver.v1.Record) PersistenceActionResult(org.meveo.persistence.PersistenceActionResult) CustomRelationshipTemplate(org.meveo.model.customEntities.CustomRelationshipTemplate) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) JpaAmpNewTx(org.meveo.jpa.JpaAmpNewTx) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 15 with Value

use of com.google.firestore.v1beta1.Value in project meveo by meveo-org.

the class Neo4jService method createEntityReferences.

/**
 * @param neo4JConfiguration
 * @param cet
 * @param fieldValues
 * @param cetFields
 * @param fields
 * @return
 * @throws BusinessException
 */
private Map<EntityRef, String> createEntityReferences(String neo4JConfiguration, CustomEntityTemplate cet, Map<String, Object> fieldValues, Map<String, CustomFieldTemplate> cetFields, Map<String, Object> fields) throws BusinessException {
    /* Collect entity references */
    final List<CustomFieldTemplate> entityReferences = cetFields.values().stream().filter(// Entity references
    customFieldTemplate -> customFieldTemplate.getFieldType().equals(CustomFieldTypeEnum.ENTITY)).filter(// Value is provided
    customFieldTemplate -> fieldValues.get(customFieldTemplate.getCode()) != null).collect(Collectors.toList());
    /* Create referenced nodes and collect relationships to create */
    // Map where the id of the target node is the key and the label of relationship is the value
    Map<EntityRef, String> relationshipsToCreate = new HashMap<>();
    for (CustomFieldTemplate entityReference : entityReferences) {
        Object referencedCetValue = fieldValues.get(entityReference.getCode());
        String referencedCetCode = entityReference.getEntityClazzCetCode();
        CustomEntityTemplate referencedCet = customFieldsCache.getCustomEntityTemplate(referencedCetCode);
        if (referencedCetValue instanceof EntityReferenceWrapper) {
            EntityReferenceWrapper wrapper = (EntityReferenceWrapper) referencedCetValue;
            if (wrapper.getUuid() == null) {
                continue;
            }
        }
        Collection<Object> values;
        if (entityReference.getStorageType().equals(CustomFieldStorageTypeEnum.LIST)) {
            if (!(referencedCetValue instanceof Collection)) {
                throw new BusinessException("Value for CFT " + entityReference.getCode() + " of CET " + cet.getCode() + " should be a collection");
            }
            values = ((Collection<Object>) referencedCetValue);
            if (referencedCet.getNeo4JStorageConfiguration() != null && referencedCet.getNeo4JStorageConfiguration().isPrimitiveEntity()) {
                fields.put(entityReference.getCode(), new ArrayList<>());
            }
        } else {
            values = Collections.singletonList(referencedCetValue);
        }
        for (Object value : values) {
            Set<EntityRef> relatedPersistedEntities = new HashSet<>();
            if (referencedCet.getNeo4JStorageConfiguration() != null && referencedCet.getNeo4JStorageConfiguration().isPrimitiveEntity()) {
                Map<String, Object> valueMap = new HashMap<>();
                valueMap.put("value", value);
                // If there is no unique constraints defined, directly merge node
                if (referencedCet.getNeo4JStorageConfiguration().getUniqueConstraints().isEmpty()) {
                    List<String> additionalLabels = getAdditionalLabels(referencedCet);
                    executePrePersist(neo4JConfiguration, referencedCet, valueMap);
                    String createdNodeId = neo4jDao.mergeNode(neo4JConfiguration, referencedCetCode, valueMap, valueMap, valueMap, additionalLabels, null);
                    if (createdNodeId != null) {
                        relatedPersistedEntities.add(new EntityRef(createdNodeId, referencedCet.getCode()));
                    }
                } else {
                    PersistenceActionResult persistenceResult = addCetNode(neo4JConfiguration, referencedCetCode, valueMap);
                    relatedPersistedEntities.addAll(persistenceResult.getPersistedEntities());
                }
                if (entityReference.getStorageType().equals(CustomFieldStorageTypeEnum.LIST)) {
                    ((List<Object>) fields.get(entityReference.getCode())).add(valueMap.get("value"));
                } else {
                    fields.put(entityReference.getCode(), valueMap.get("value"));
                }
            } else {
                // Referenced CET is not primitive
                if (value instanceof Map && referencedCet.getAvailableStorages().contains(DBStorageType.NEO4J)) {
                    Map<String, Object> valueMap = (Map<String, Object>) value;
                    PersistenceActionResult persistenceResult = addCetNode(neo4JConfiguration, referencedCet, valueMap);
                    relatedPersistedEntities.addAll(persistenceResult.getPersistedEntities());
                } else if (value instanceof String) {
                    // If entity reference's value is a string and the entity reference is not primitive, then the value is likely the UUID of the referenced node
                    handleUuidReference(neo4JConfiguration, cet, relationshipsToCreate, entityReference, referencedCet, value);
                } else if (value instanceof EntityReferenceWrapper) {
                    handleUuidReference(neo4JConfiguration, cet, relationshipsToCreate, entityReference, referencedCet, ((EntityReferenceWrapper) value).getUuid());
                } else if (value instanceof Collection) {
                    for (Object item : (Collection<?>) value) {
                        if (item instanceof String) {
                            handleUuidReference(neo4JConfiguration, cet, relationshipsToCreate, entityReference, referencedCet, value);
                        }
                    }
                } else if (referencedCet.getAvailableStorages().contains(DBStorageType.NEO4J)) {
                    throw new IllegalArgumentException("CET " + referencedCetCode + " should be a primitive entity");
                }
            }
            if (relatedPersistedEntities != null) {
                String relationshipName = Optional.ofNullable(entityReference.getRelationshipName()).orElseGet(() -> entityReference.getRelationship() != null ? entityReference.getRelationship().getName() : null);
                if (relationshipName == null) {
                    throw new BusinessException(entityReference.getAppliesTo() + "#" + entityReference.getCode() + ": Relationship name must be provided !");
                }
                for (EntityRef entityRef : relatedPersistedEntities) {
                    relationshipsToCreate.put(entityRef, relationshipName);
                }
            }
        }
    }
    return relationshipsToCreate;
}
Also used : CustomRelationshipTemplateService(org.meveo.service.custom.CustomRelationshipTemplateService) CrossStorageTransaction(org.meveo.persistence.CrossStorageTransaction) CustomPersistenceService(org.meveo.persistence.CustomPersistenceService) Date(java.util.Date) ELException(org.meveo.elresolver.ELException) LoggerFactory(org.slf4j.LoggerFactory) RepositoryService(org.meveo.service.storage.RepositoryService) StringUtils(org.meveo.commons.utils.StringUtils) ScriptInstanceService(org.meveo.service.script.ScriptInstanceService) CustomEntityTemplateUniqueConstraint(org.meveo.model.crm.CustomEntityTemplateUniqueConstraint) CustomRelationshipTemplate(org.meveo.model.customEntities.CustomRelationshipTemplate) Future(java.util.concurrent.Future) Repository(org.meveo.model.storage.Repository) Matcher(java.util.regex.Matcher) TransactionAttributeType(javax.ejb.TransactionAttributeType) MeveoJpa(org.meveo.jpa.MeveoJpa) Asynchronous(javax.ejb.Asynchronous) CustomFieldValue(org.meveo.model.crm.custom.CustomFieldValue) Map(java.util.Map) CETUtils(org.meveo.api.CETUtils) AsyncResult(javax.ejb.AsyncResult) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) Value(org.neo4j.driver.v1.Value) PatternSyntaxException(java.util.regex.PatternSyntaxException) ApplicationProvider(org.meveo.util.ApplicationProvider) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) CustomEntityInstance(org.meveo.model.customEntities.CustomEntityInstance) Neo4jRelationship(org.meveo.persistence.neo4j.graph.Neo4jRelationship) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Instant(java.time.Instant) Transaction(org.neo4j.driver.v1.Transaction) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) BusinessException(org.meveo.admin.exception.BusinessException) CustomEntityTemplate(org.meveo.model.customEntities.CustomEntityTemplate) Node(org.neo4j.driver.v1.types.Node) List(java.util.List) Response(javax.ws.rs.core.Response) CustomFieldStorageTypeEnum(org.meveo.model.crm.custom.CustomFieldStorageTypeEnum) HttpURLConnection(org.apache.commons.httpclient.util.HttpURLConnection) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) Entry(java.util.Map.Entry) CustomFieldsCacheContainerProvider(org.meveo.cache.CustomFieldsCacheContainerProvider) Optional(java.util.Optional) CustomEntityTemplateUtils(org.meveo.service.custom.CustomEntityTemplateUtils) Pattern(java.util.regex.Pattern) StatementResult(org.neo4j.driver.v1.StatementResult) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) BusinessEntity(org.meveo.model.BusinessEntity) PaginationConfiguration(org.meveo.admin.util.pagination.PaginationConfiguration) RemoteAuthenticationException(org.meveo.export.RemoteAuthenticationException) JpaAmpNewTx(org.meveo.jpa.JpaAmpNewTx) NODE_ID(org.meveo.persistence.neo4j.base.Neo4jDao.NODE_ID) EntityReferenceWrapper(org.meveo.model.crm.EntityReferenceWrapper) BasicAuthentication(org.jboss.resteasy.client.jaxrs.BasicAuthentication) PersistenceActionResult(org.meveo.persistence.PersistenceActionResult) HashMap(java.util.HashMap) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) Updated(org.meveo.event.qualifier.Updated) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Record(org.neo4j.driver.v1.Record) HashSet(java.util.HashSet) Inject(javax.inject.Inject) JacksonUtil(org.meveo.model.persistence.JacksonUtil) Removed(org.meveo.event.qualifier.Removed) Provider(org.meveo.model.crm.Provider) CustomFieldTemplateService(org.meveo.service.crm.impl.CustomFieldTemplateService) MeveoValueExpressionWrapper(org.meveo.service.base.MeveoValueExpressionWrapper) TransactionAttribute(javax.ejb.TransactionAttribute) Neo4jDao(org.meveo.persistence.neo4j.base.Neo4jDao) Event(javax.enterprise.event.Event) InvalidCustomFieldException(org.meveo.exceptions.InvalidCustomFieldException) Logger(org.slf4j.Logger) DBStorageType(org.meveo.model.persistence.DBStorageType) Created(org.meveo.event.qualifier.Created) EntityManagerWrapper(org.meveo.jpa.EntityManagerWrapper) CustomFieldTypeEnum(org.meveo.model.crm.custom.CustomFieldTypeEnum) Neo4jEntity(org.meveo.persistence.neo4j.graph.Neo4jEntity) CustomFieldIndexTypeEnum(org.meveo.model.crm.custom.CustomFieldIndexTypeEnum) InternalNode(org.neo4j.driver.internal.InternalNode) Relationship(org.neo4j.driver.v1.types.Relationship) Comparator(java.util.Comparator) Collections(java.util.Collections) EntityRef(org.meveo.persistence.scheduler.EntityRef) Values(org.neo4j.driver.v1.Values) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BusinessException(org.meveo.admin.exception.BusinessException) CustomEntityTemplate(org.meveo.model.customEntities.CustomEntityTemplate) EntityReferenceWrapper(org.meveo.model.crm.EntityReferenceWrapper) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) Collection(java.util.Collection) PersistenceActionResult(org.meveo.persistence.PersistenceActionResult) List(java.util.List) ArrayList(java.util.ArrayList) EntityRef(org.meveo.persistence.scheduler.EntityRef) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

Test (org.junit.Test)126 Value (com.google.firestore.v1.Value)108 ArrayValue (com.google.firestore.v1.ArrayValue)73 LinkedHashSet (java.util.LinkedHashSet)71 ObjectValue (com.google.firebase.firestore.model.ObjectValue)53 NullValue (com.google.protobuf.NullValue)50 MapValue (com.google.firestore.v1.MapValue)47 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)25 Value (com.google.datastore.v1.Value)20 Map (java.util.Map)20 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)17 List (java.util.List)17 Record (org.apache.avro.generic.GenericData.Record)16 SchemaAndRecord (org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord)16 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)16 Set (java.util.Set)14 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)13 Nullable (androidx.annotation.Nullable)10 Value (com.google.privacy.dlp.v2.Value)9