public PolymorphicForeignKeyInChildCollectionBaseMapper( final ObjectAssociation objectAssociation, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) { super(objectAssociation, parameterBase, lookup, objectMapperLookup, abstractAutoMapper, field); classColumnName = Sql.identifier(Sql.sqlName(getForeignKeyName() + "_cls")); itemIdColumnName = Sql.identifier("item_id"); polyIdMapper = new JdbcPolymorphicObjectReferenceMapping(itemIdColumnName); oidGenerator = IsisContext.getPersistenceSession().getOidGenerator(); }
protected PersistenceSession getPersistenceSession() { return IsisContext.getPersistenceSession(); }
private static PersistenceSession getPersistenceSession() { return IsisContext.getPersistenceSession(); }
protected List<ObjectAdapter> getServiceAdapters() { return IsisContext.getPersistenceSession().getServices(); }
public AdapterManager getAdapterManager() { return IsisContext.getPersistenceSession().getAdapterManager(); }
@Override public Persistor getPersistenceSession() { return IsisContext.getPersistenceSession(); }
protected ServicesInjector getServicesInjector() { return IsisContext.getPersistenceSession().getServicesInjector(); }
@Override public void process(final RequestContext context) throws IOException { AuthenticationSession session = context.getSession(); if (session == null) { session = new AnonymousSession(); } try { final String objectId = context.getParameter("_" + OBJECT); final String version = context.getParameter("_" + VERSION); final String formId = context.getParameter("_" + FORM_ID); String resultName = context.getParameter("_" + RESULT_NAME); resultName = resultName == null ? RequestContext.RESULT : resultName; final String override = context.getParameter("_" + RESULT_OVERRIDE); String message = context.getParameter("_" + MESSAGE); final ObjectAdapter adapter = context.getMappedObject(objectId); final List<ObjectAssociation> fields = adapter .getSpecification() .getAssociations( Contributed.EXCLUDED, ObjectAssociation.Filters.dynamicallyVisible(session, adapter, where)); for (final ObjectAssociation objectAssociation : fields) { if (objectAssociation.isVisible(session, adapter, where).isVetoed()) { throw new NotLoggedInException(); } } final FormState entryState = validateObject(context, adapter, fields); final Version adapterVersion = adapter.getVersion(); final Version formVersion = context.getVersion(version); if (formVersion != null && adapterVersion.different(formVersion)) { IsisContext.getMessageBroker() .addMessage( "The " + adapter.getSpecification().getSingularName() + " was edited " + "by another user (" + adapterVersion.getUser() + "). Please make your changes based on their changes."); final String view = context.getParameter("_" + ERROR); context.setRequestPath(view, Dispatcher.EDIT); entryState.setForm(formId); context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST); context.addVariable(resultName, objectId, Scope.REQUEST); if (override != null) { context.addVariable(resultName, override, Scope.REQUEST); } } else if (entryState.isValid()) { changeObject(context, adapter, entryState, fields); if (adapter.isTransient()) { IsisContext.getPersistenceSession().makePersistent(adapter); context.unmapObject(adapter, Scope.REQUEST); } String view = context.getParameter("_" + VIEW); final String id = context.mapObject(adapter, Scope.REQUEST); context.addVariable(resultName, id, Scope.REQUEST); if (override != null) { context.addVariable(resultName, override, Scope.REQUEST); } final int questionMark = view == null ? -1 : view.indexOf("?"); if (questionMark > -1) { final String params = view.substring(questionMark + 1); final int equals = params.indexOf("="); context.addVariable( params.substring(0, equals), params.substring(equals + 1), Scope.REQUEST); view = view.substring(0, questionMark); } context.setRequestPath(view); if (message == null) { message = "Saved changes to " + adapter.getSpecification().getSingularName(); } else if (message.equals("")) { message = null; } if (message != null) { final MessageBroker messageBroker = IsisContext.getMessageBroker(); messageBroker.addMessage(message); } } else { final String view = context.getParameter("_" + ERROR); context.setRequestPath(view, Dispatcher.EDIT); entryState.setForm(formId); context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST); context.addVariable(resultName, objectId, Scope.REQUEST); if (override != null) { context.addVariable(resultName, override, Scope.REQUEST); } final MessageBroker messageBroker = IsisContext.getMessageBroker(); messageBroker.addWarning(entryState.getError()); } } catch (final RuntimeException e) { IsisContext.getMessageBroker().getMessages(); IsisContext.getMessageBroker().getWarnings(); throw e; } }
private FormState validateObject( final RequestContext context, final ObjectAdapter object, final List<ObjectAssociation> fields) { final FormState formState = new FormState(); for (int i = 0; i < fields.size(); i++) { final ObjectAssociation field = fields.get(i); final String fieldId = field.getId(); String newEntry = context.getParameter(fieldId); if (fields.get(i).isOneToManyAssociation()) { continue; } if (fields .get(i) .isVisible(IsisContext.getAuthenticationSession(), object, where) .isVetoed()) { continue; } if (field.isUsable(IsisContext.getAuthenticationSession(), object, where).isVetoed()) { continue; } if (newEntry != null && newEntry.equals("-OTHER-")) { newEntry = context.getParameter(fieldId + "-other"); } if (newEntry == null) { // TODO duplicated in EditObject; line 97 final ObjectSpecification spec = field.getSpecification(); if (spec.isOfType(IsisContext.getSpecificationLoader().loadSpecification(boolean.class)) || spec.isOfType( IsisContext.getSpecificationLoader().loadSpecification(Boolean.class))) { newEntry = FALSE; } else { continue; } } final FieldEditState fieldState = formState.createField(fieldId, newEntry); Consent consent = null; if (field.isMandatory() && (newEntry.equals("") || newEntry.equals("NULL"))) { consent = new Veto(field.getName() + " required"); formState.setError("Not all fields have been set"); } else if (field.getSpecification().containsFacet(ParseableFacet.class)) { try { final ParseableFacet facet = field.getSpecification().getFacet(ParseableFacet.class); final ObjectAdapter originalValue = field.get(object); Localization localization = IsisContext.getLocalization(); final ObjectAdapter newValue = facet.parseTextEntry(originalValue, newEntry, localization); consent = ((OneToOneAssociation) field).isAssociationValid(object, newValue); fieldState.setValue(newValue); } catch (final TextEntryParseException e) { consent = new Veto(e.getMessage()); // formState.setError("Not all fields have been entered correctly"); } } else { final ObjectAdapter associate = newEntry.equals("null") ? null : context.getMappedObject(newEntry); if (associate != null) { IsisContext.getPersistenceSession().resolveImmediately(associate); } consent = ((OneToOneAssociation) field).isAssociationValid(object, associate); fieldState.setValue(associate); } if (consent.isVetoed()) { fieldState.setError(consent.getReason()); formState.setError("Not all fields have been entered correctly"); } } // TODO check the state of the complete object. return formState; }