use of com.manydesigns.portofino.model.database.ForeignKey in project Portofino by ManyDesigns.
the class CrudAction method saveConfiguration.
@Override
protected boolean saveConfiguration(Object configuration) {
CrudConfiguration crudConfiguration = (CrudConfiguration) configuration;
List<SelectionProviderReference> sps = new ArrayList<>(crudConfiguration.getSelectionProviders());
crudConfiguration.getSelectionProviders().clear();
crudConfiguration.persistence = persistence;
crudConfiguration.init();
sps.forEach(sp -> {
ForeignKey fk = DatabaseLogic.findForeignKeyByName(crudConfiguration.getActualTable(), sp.getSelectionProviderName());
if (fk != null) {
sp.setForeignKeyName(sp.getSelectionProviderName());
sp.setSelectionProviderName(null);
}
if (sp.getSelectionProviderName() != null || sp.getForeignKeyName() != null) {
crudConfiguration.getSelectionProviders().add(sp);
}
});
List<CrudProperty> existingProperties = this.crudConfiguration.getProperties();
List<CrudProperty> configuredProperties = crudConfiguration.getProperties();
List<CrudProperty> newProperties = configuredProperties.stream().map(p1 -> {
Optional<CrudProperty> maybeP2 = existingProperties.stream().filter(p2 -> p1.getName().equals(p2.getName())).findFirst();
CrudProperty p2 = maybeP2.orElse(new CrudProperty());
p2.setName(p1.getName());
p2.setEnabled(p1.isEnabled());
p2.setInsertable(p1.isInsertable());
p2.setInSummary(p1.isInSummary());
p2.setLabel(p1.getLabel());
p2.setSearchable(p1.isSearchable());
p2.setUpdatable(p1.isUpdatable());
return p2;
}).collect(Collectors.toList());
crudConfiguration.setProperties(newProperties);
return super.saveConfiguration(crudConfiguration);
}
use of com.manydesigns.portofino.model.database.ForeignKey in project Portofino by ManyDesigns.
the class ConfigurationForm method writeTo.
public void writeTo(ManyToManyConfiguration m2mConfiguration) {
m2mConfiguration.setViewType(viewType);
m2mConfiguration.setDatabase(database);
m2mConfiguration.setQuery(query);
m2mConfiguration.setOneExpression(oneExpression);
m2mConfiguration.setOnePropertyName(onePropertyName);
if (StringUtils.isEmpty(oneSpName)) {
m2mConfiguration.setOneSelectionProvider(null);
} else {
boolean found = false;
for (ForeignKey fk : m2mConfiguration.getActualRelationTable().getForeignKeys()) {
if (fk.getName().equals(oneSpName)) {
SelectionProviderReference ref = new SelectionProviderReference();
ref.setForeignKeyName(oneSpName);
m2mConfiguration.setOneSelectionProvider(ref);
found = true;
break;
}
}
if (!found) {
for (ModelSelectionProvider sp : m2mConfiguration.getActualRelationTable().getSelectionProviders()) {
if (sp.getName().equals(oneSpName)) {
SelectionProviderReference ref = new SelectionProviderReference();
ref.setSelectionProviderName(oneSpName);
m2mConfiguration.setOneSelectionProvider(ref);
break;
}
}
}
}
if (StringUtils.isEmpty(manySpName) || m2mConfiguration.getActualRelationTable() == null) {
m2mConfiguration.setManySelectionProvider(null);
} else {
boolean found = false;
for (ForeignKey fk : m2mConfiguration.getActualRelationTable().getForeignKeys()) {
if (fk.getName().equals(manySpName)) {
SelectionProviderReference ref = new SelectionProviderReference();
ref.setForeignKeyName(manySpName);
m2mConfiguration.setManySelectionProvider(ref);
found = true;
break;
}
}
if (!found) {
for (ModelSelectionProvider sp : m2mConfiguration.getActualRelationTable().getSelectionProviders()) {
if (sp.getName().equals(manySpName)) {
SelectionProviderReference ref = new SelectionProviderReference();
ref.setSelectionProviderName(manySpName);
m2mConfiguration.setManySelectionProvider(ref);
break;
}
}
}
}
}
use of com.manydesigns.portofino.model.database.ForeignKey in project Portofino by ManyDesigns.
the class SessionFactoryBuilder method mapRelationships.
public void mapRelationships(Table table) throws NotFoundException, CannotCompileException {
for (ForeignKey foreignKey : table.getForeignKeys()) {
if (checkValidFk(foreignKey)) {
mapManyToOne(foreignKey);
mapOneToMany(foreignKey);
}
}
}
Aggregations