/*
|--------------------------------------------------------------------------
| Entity
|--------------------------------------------------------------------------
330566
function ParcelTrackerInfo(obj) {
    this.attempts = obj.attempts
    this.id = obj.id
    this.state = obj.state
    this.deliveryDate = obj.deliveryDate
    this.states = obj.states,
    this.origin = obj.origin,
    this.destiny = obj.destiny
    this.trackerWebsite = pitney.getLink(this.id)
}
230906
function createCorreosEsEntity(id, html) {

    let $ = parser.load(html)

    let table2 = $('#Table2').get(0);

    let states = []
    const fields = ['date', 'info']
    if (table2.children.length === 0 ||
        (table2.children[1] !== undefined
        && table2.children[1].data !== undefined
        && table2.children[1].data.trim() === 'fin tabla descripciones'))
        return null;

    table2.children.forEach(function (elem) {

        if (elem.attribs !== undefined && elem.attribs.class.trim() === 'txtCabeceraTabla') {
            let state = {}
            elem.children.forEach(function (_child) {
                if (_child.attribs !== undefined && _child.attribs.class !== undefined) {
                    let _class = _child.attribs.class.trim()
                    if (_class === 'txtDescripcionTabla') {
                        state['date'] = moment.tz(_child.children[0].data.trim(), "DD/MM/YYYY", zone).format()
                    } else if (_class === 'txtContenidoTabla' || _class === 'txtContenidoTablaOff') {
                        state['state'] = _child.children[1].children[0].data.trim()
                        if (_child.children[1].attribs !== undefined && _child.children[1].attribs !== undefined
                            && _child.children[1].attribs.title) {
                            state['title'] = _child.children[1].attribs.title.trim()
                        }
                    }
                }
            })
            if (Object.keys(state).length > 0) {
                states.push(state)
            }
        }

    })

    return new CorreosESInfo({
        'id': id,
        'state': states[states.length - 1].state,
        'states': states.reverse()
    })
}
892220
@Override
    public T create(T entity) {
        EntityManager entityManager = getEntityManager();
        entityManager.persist(entity);
        return entity;
    }
178923
function createEntity(html, id) {
    let $ = parser.load(html)

    let trs = $('.tabproperty table tr').slice(2)

    let states = utils.tableParser(trs, {
        date: {
            idx: 1,
            mandatory: true,
            parser: e => moment.tz(e, "MM/DD/YYYY hh:mm a", zone).format()
        },
        country: {
            idx: 3,
            mandatory: true
        },
        area: {
            idx: 5,
            mandatory: true
        },
        state: {
            idx: 7,
            mandatory: true
        }
    }).map(line => {
        return {
            date: line.date,
            state: line.state,
            area: line.country + ' - ' + line.area
        }
    }).reverse()

    return new EntityInfo({
        id: id,
        states: states
    })
}
1053440
function _processNode(node, level) {
        var nodeData = null;
        
        // entity tag
        if (w.isReadOnly === false && node.attr('_entity') && (node.attr('_tag') || node.attr('_note'))) {
            var id = node.attr('name');
            var entity = w.entitiesManager.getEntity(id);
            var type = node.attr('_type');
            var tag = node.attr('_tag');
            if (tag == null) {
                tag = w.schemaManager.mapper.getParentTag(type);
            }
            
            nodeData = {
                text: tag,
                li_attr: {name: id}, // 'class': type}
                state: {opened: level < 3}
            };
            
            if (w.schemaManager.mapper.isEntityTypeNote(type)) {
                var content = w.schemaManager.mapper.getNoteContentForEntity(entity);
                switch($.type(content)) {
                    case 'array':
                        nodeData.children = [];
                        for (var i = 0; i < content.length; i++) {
                            nodeData.children.push({
                                text: content[i],
                                li_attr: {name: id}
                            });
                        }
                        break;
                    case 'string':
                        nodeData.children = [];
                        nodeData.children.push({
                            text: content,
                            li_attr: {name: id}
                        });
                        break;
                    case 'object':
                        if (content.nodeType !== undefined) {
                            var root = $(tag, content).first();
                            
                            var processChildren = function(children, parent, id) {
                                children.each(function(index, el) {
                                    if (parent.children == null) parent.children = [];
                                    var childData = {
                                        text: el.nodeName,
                                        li_attr: {name: id}
                                    };
                                    parent.children.push(childData);
                                    
                                    processChildren($(el).children(), childData, id);
                                });
                            }
                            
                            processChildren(root.children(), nodeData, id);
                        }
                }
            }
            
        // structure tag
        } else if (node.attr('_tag')) {
            var tag = node.attr('_tag');
            if (w.isReadOnly === false || (w.isReadOnly && (tag === w.root || tree.tagFilter.indexOf(tag.toLowerCase()) !== -1))) {
                var id = node.attr('id');
                var info = w.structs[id];
                
                if (info == undefined) {
                    // redo/undo re-added a struct check
                    info = w.deletedStructs[id];
                    if (info != undefined) {
                        w.structs[id] = info;
                        delete w.deletedStructs[id];
                    }
                }
                
                if (info) {
                    var text = info._tag;
                    if (w.isReadOnly) {
                        if (tag === w.root) {
                            text = w.root;// || w.currentDocId;
                        } else {
                            text = w.utilities.getTitleFromContent(node.text());
                        }
                    }
                    nodeData = {
                        text: text,
                        li_attr: {name: id},
                        state: {opened: level < 3}
                    };
                }
            }
        }
        if (nodeData !== null) {
            nodeData.level = level;
            // FIXME we really shouldn't have this hardcoded here
            // manually set the level for CWRC schema to have proper sorting in readOnly mode
            if (w.schemaManager.schemaId === 'cwrcEntry') {
                var subtype = node.attr('subtype');
                if (subtype !== undefined) {
                    nodeData.level = parseInt(subtype);
                }
            }
        }
        
        return nodeData;
    }
543029
public function execute()
    {
        $entity = $this->aggregate->getEntityObject();
        $wrappedEntity = $this->aggregate->getWrappedEntity();
        $mapper = $this->aggregate->getMapper();

        if ($mapper->fireEvent('storing', $wrappedEntity) === false) {
            return false;
        }

        $this->preStoreProcess();

        /*
         * We will test the entity for existence
         * and run a creation if it doesn't exists
         */
        if (!$this->aggregate->exists()) {
            if ($mapper->fireEvent('creating', $wrappedEntity) === false) {
                return false;
            }

            $this->insert();

            $mapper->fireEvent('created', $wrappedEntity, false);
        } elseif ($this->aggregate->isDirty()) {
            if ($mapper->fireEvent('updating', $wrappedEntity) === false) {
                return false;
            }
            $this->update();

            $mapper->fireEvent('updated', $wrappedEntity, false);
        }

        $this->postStoreProcess();

        $mapper->fireEvent('stored', $wrappedEntity, false);

        // Once the object is stored, add it to the Instance cache
        $key = $this->aggregate->getEntityKeyValue();

        if (!$mapper->getInstanceCache()->has($key)) {
            $mapper->getInstanceCache()->add($entity, $key);
        }

        $this->syncForeignKeyAttributes();

        $wrappedEntity->unwrap();

        return $entity;
    }
1108856
public function save($entity)
    {

        $objectManager = $this->getObjectManager();

        //@TODO UnitOfWork::STATE_NEW == $em->getUnitOfWork()->getEntityState($entity)
        //@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-objects.html#entity-state
        $objectManager->persist($entity);
        $objectManager->flush();
    }
1126717
public function createByTypeAction($id, Request $request)
    {
        $contentType = $this->contentTypeManager->getContentTypeById($id);

        if ($contentType === null) {
            throw EntityNotFoundException::fromClassNameAndIdentifier(
                $this->configurationManager->getEntityClass('content_type'),
                [$id]
            );
        }

        $contentEntityClass = $this->configurationManager->getEntityClass('content');
        $content = new $contentEntityClass;
        $content->setContentType($contentType);

        $form = $this->createForm(ContentType::class, $content, [
            'action' => $this->generateUrl('sherlockode_acb_content_create_by_type', ['id' => $contentType->getId()]),
            'contentType' => $content->getContentType(),
        ]);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $this->om->persist($content);
            $this->om->flush();

            return $this->redirectToRoute('sherlockode_acb_content_edit', ['id' => $content->getId()]);
        }

        return $this->render('@SherlockodeAdvancedContent/Content/edit_content.html.twig', [
            'form' => $form->createView(),
            'is_ajax' => $request->isXmlHttpRequest(),
        ]);
    }
642714
public function delete($id)
    {
        $this->beforeDelete($id);
        $this->entity->delete($id);
        $this->afterDelete($id);
    }
632465
public function registerEntity(Entity $entity)
    {
        Logger::get()->debug('Registering entity ' . get_class($entity) . ":{$entity->id}...");
        self::$entities[get_called_class()][$entity->id] = $entity;
        Logger::get()->debug('Registered.');
    }
1232826
private function buildEntity()
    {
        $classname = $this->classname;
        if (class_exists($classname) && $this->isRegistryEntity(new $classname())) {
            $this->entity = new $classname();
            $this->buildEntityClass();
        } else {
            $this->entity = new \stdClass();
            $this->buildStdClass();
        }
    }
966205
function EntityInfo(obj) {
    const {id, states, destinStates} = obj

    this.id = id
    this.states = states
    this.destinStates = destinStates

    this.trackerWebsite = tracker.getLink(id)
}
270992
public function deleteAction() {
        try {
            if(sizeOf($this->dispatcher->getParams()) == 0) {
                throw new Exception('Invalid Entity Id Passed In', 400);
            }
            $entity = $this->validateEntityId($this->dispatcher->getParam(0));
            $this->deleteActionInternal($entity);
        } catch(Exception $e) {
            $this->handleError($e);
        } catch(ValidationException $e) {
            $this->handleValidationError($e);
        } catch(AclException $e) {
            $this->handleAclError($e);
        }
    }
98918
function onSuccess() {
            /**
             * Make sure to clear the cache for this Entity Kind
             */
            if (_this.constructor.__hasCache(options)) {
                return _this.constructor.clearCache()
                    .then(() => _this)
                    .catch((err) => {
                        let msg = 'Error while clearing the cache after saving the entity.';
                        msg += 'The entity has been saved successfully though. ';
                        msg += 'Both the cache error and the entity saved have been attached.';
                        const cacheError = new Error(msg);
                        cacheError.__entity = _this;
                        cacheError.__cacheError = err;
                        throw cacheError;
                    });
            }

            return _this;
        }
728846
public function create(Entity $entity)
    {
        $result = $this->events->shouldExecute($entity, 'before', 'create');
        if (!$result) {
            return false;
        }
        $result = $this->doCreate($entity);
        $this->events->shouldExecute($entity, 'after', 'create');
        return $result;
    }
322302
private void buildEntityFromCursor(Object entity, HashMap obj, EntityType entityType)
    {
        Iterator<Attribute> iter = entityType.getAttributes().iterator();
        while (iter.hasNext())
        {
            Attribute attribute = iter.next();
            Field field = (Field) attribute.getJavaMember();
            if (field.isAnnotationPresent(Id.class))
            {
                PropertyAccessorHelper.set(entity, field, obj.get(ID));
            }
            else
            {
                PropertyAccessorHelper.set(entity, field, obj.get(((AbstractAttribute) attribute).getJPAColumnName()));
            }

        }
    }
996513
public void addEntity(Entity entity){
		boolean delayed = updating || familyManager.notifying();
		entityManager.addEntity(entity, delayed);
	}