Search in sources :

Example 1 with Entity

use of com.liferay.ide.service.core.model.Entity in project liferay-ide by liferay.

the class RelationshipsBindingImpl method _removeRelationship.

private void _removeRelationship(RelationshipObject relObject) {
    String fromName = relObject.getFromName();
    String toName = relObject.getToName();
    Entity fromEntity = EntityRelationshipService.findEntity(fromName, _serviceBuilder());
    Entity toEntity = EntityRelationshipService.findEntity(toName, _serviceBuilder());
    Column primaryKeyColumn = _findPrimaryKey(toEntity);
    if (primaryKeyColumn != null) {
        String primaryKeyName = primaryKeyColumn.getName().content();
        if (!empty(primaryKeyName)) {
            Column columnToRemove = null;
            for (Column column : fromEntity.getColumns()) {
                if (primaryKeyName.equals(column.getName().content())) {
                    columnToRemove = column;
                    break;
                }
            }
            if (columnToRemove != null) {
                fromEntity.getColumns().remove(columnToRemove);
            }
        }
    }
}
Also used : Entity(com.liferay.ide.service.core.model.Entity) Column(com.liferay.ide.service.core.model.Column)

Example 2 with Entity

use of com.liferay.ide.service.core.model.Entity in project liferay-ide by liferay.

the class RelationshipsBindingImpl method _refreshRelationships.

private void _refreshRelationships() {
    _relationships.clear();
    Map<String, String> primaryKeys = new HashMap<>();
    for (Entity entity : _serviceBuilder().getEntities()) {
        Column primaryKeyColumn = _findPrimaryKey(entity);
        if ((primaryKeyColumn != null) && !empty(primaryKeyColumn.getName().content())) {
            primaryKeys.put(primaryKeyColumn.getName().content(), entity.getName().content());
        }
    }
    for (Entity entity : _serviceBuilder().getEntities()) {
        for (Column column : entity.getColumns()) {
            if (!column.isPrimary().content()) {
                String columnName = column.getName().content();
                String entityName = primaryKeys.get(columnName);
                if (entityName != null) {
                    _relationships.add(new RelationshipObject(entity.getName().content(), entityName));
                }
            }
        }
    }
}
Also used : Entity(com.liferay.ide.service.core.model.Entity) HashMap(java.util.HashMap) Column(com.liferay.ide.service.core.model.Column)

Example 3 with Entity

use of com.liferay.ide.service.core.model.Entity in project liferay-ide by liferay.

the class ServiceXmlTests method testEntityReferenceService.

@Test
public void testEntityReferenceService() throws Exception {
    ServiceBuilder sb = ServiceBuilder6xx.TYPE.instantiate(new RootXmlResource(new XmlResourceStore(this.getClass().getResourceAsStream("files/entity-reference-test.xml"))));
    Entity foo = sb.getEntities().get(0);
    Entity bar = sb.getEntities().get(1);
    ElementList<Relationship> relationships = sb.getRelationships();
    assertEquals(1, relationships.size());
    Entity to = sb.getRelationships().get(0).getToEntity().target();
    Entity from = sb.getRelationships().get(0).getFromEntity().target();
    assertEquals(to, foo);
    assertEquals(from, bar);
}
Also used : Entity(com.liferay.ide.service.core.model.Entity) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) Relationship(com.liferay.ide.service.core.model.Relationship) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) ServiceBuilder(com.liferay.ide.service.core.model.ServiceBuilder) Test(org.junit.Test)

Example 4 with Entity

use of com.liferay.ide.service.core.model.Entity in project liferay-ide by liferay.

the class AddDefaultColumnsAction method run.

@Override
protected Object run(Presentation context) {
    Element element = context.part().getLocalModelElement();
    if (element instanceof Entity) {
        String entityName = ((Entity) element).getName().content();
        if (CoreUtil.isNullOrEmpty(entityName)) {
            String title = "Add Liferay Default Columns";
            String message = "The entity name must be specified.";
            MessageDialog.openInformation(UIUtil.getActiveShell(), title, message);
        } else {
            IFile serviceXML = element.adapt(IFile.class);
            new ServiceBuilderDescriptorHelper(serviceXML.getProject()).addDefaultColumns(entityName);
        }
    }
    return null;
}
Also used : Entity(com.liferay.ide.service.core.model.Entity) IFile(org.eclipse.core.resources.IFile) Element(org.eclipse.sapphire.Element) ServiceBuilderDescriptorHelper(com.liferay.ide.service.core.operation.ServiceBuilderDescriptorHelper)

Example 5 with Entity

use of com.liferay.ide.service.core.model.Entity in project liferay-ide by liferay.

the class RelationshipResource method _persistRelationship.

private void _persistRelationship() {
    Element element = parent().element();
    ServiceBuilder serviceBuilder = element.nearest(ServiceBuilder.class);
    String fromName = _relationshipObject.getFromName();
    String toName = _relationshipObject.getToName();
    Entity fromEntity = EntityRelationshipService.findEntity(fromName, serviceBuilder);
    Entity toEntity = EntityRelationshipService.findEntity(toName, serviceBuilder);
    if ((fromEntity != null) && (toEntity != null)) {
        Column primaryKeyColumn = null;
        for (Column column : toEntity.getColumns()) {
            if (column.isPrimary().content()) {
                primaryKeyColumn = column;
                break;
            }
        }
        if (primaryKeyColumn != null) {
            Column column = fromEntity.getColumns().insert();
            column.setName(primaryKeyColumn.getName().content());
            column.setType("long");
        }
    }
}
Also used : Entity(com.liferay.ide.service.core.model.Entity) Column(com.liferay.ide.service.core.model.Column) Element(org.eclipse.sapphire.Element) ServiceBuilder(com.liferay.ide.service.core.model.ServiceBuilder)

Aggregations

Entity (com.liferay.ide.service.core.model.Entity)5 Column (com.liferay.ide.service.core.model.Column)3 ServiceBuilder (com.liferay.ide.service.core.model.ServiceBuilder)2 Element (org.eclipse.sapphire.Element)2 Relationship (com.liferay.ide.service.core.model.Relationship)1 ServiceBuilderDescriptorHelper (com.liferay.ide.service.core.operation.ServiceBuilderDescriptorHelper)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 RootXmlResource (org.eclipse.sapphire.modeling.xml.RootXmlResource)1 XmlResourceStore (org.eclipse.sapphire.modeling.xml.XmlResourceStore)1 Test (org.junit.Test)1