Search in sources :

Example 1 with Column

use of com.liferay.ide.service.core.model.Column 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 Column

use of com.liferay.ide.service.core.model.Column 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 Column

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

the class ColumnImageService method compute.

@Override
public ImageData compute() {
    ImageData imageData = null;
    Column column = context(Column.class);
    if (column.isPrimary().content()) {
        imageData = _IMG_COLUMN_PRIMARY;
    } else {
        imageData = _IMG_COLUMN;
    }
    return imageData;
}
Also used : Column(com.liferay.ide.service.core.model.Column) ImageData(org.eclipse.sapphire.ImageData)

Example 4 with Column

use of com.liferay.ide.service.core.model.Column 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

Column (com.liferay.ide.service.core.model.Column)4 Entity (com.liferay.ide.service.core.model.Entity)3 ServiceBuilder (com.liferay.ide.service.core.model.ServiceBuilder)1 HashMap (java.util.HashMap)1 Element (org.eclipse.sapphire.Element)1 ImageData (org.eclipse.sapphire.ImageData)1