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);
}
}
}
}
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));
}
}
}
}
}
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;
}
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");
}
}
}