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