Exemplo n.º 1
0
 /** Convenience method to close all sessions. */
 public static void closeAllSessions() {
   LOG.info("closing all instances");
   final IsisContext instance = getInstance();
   if (instance != null) {
     instance.closeAllSessionsInstance();
   }
 }
Exemplo n.º 2
0
 private void ensureInTransaction() {
   if (transactionMode == TransactionMode.UNCHAINED) {
     ensureThatContext(IsisContext.inTransaction(), is(true));
     ensureInHibernateTransaction();
   } else {
     ensureInSession();
     if (IsisContext.inTransaction()) {
       ensureInHibernateTransaction();
     } else {
       getTransactionManager().startTransaction();
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public String parseAndValidate(
     final ScalarModel scalarModel, final String proposedPojoAsStr) {
   final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
   ParseableFacet parseableFacet = property.getFacet(ParseableFacet.class);
   if (parseableFacet == null) {
     parseableFacet = property.getSpecification().getFacet(ParseableFacet.class);
   }
   try {
     final ObjectAdapter parentAdapter =
         scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
     final ObjectAdapter currentValue = property.get(parentAdapter);
     Localization localization = IsisContext.getLocalization();
     final ObjectAdapter proposedAdapter =
         parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr, localization);
     final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter);
     return valid.isAllowed() ? null : valid.getReason();
   } catch (final ConcurrencyException ex) {
     // disregard concurrency exceptions because will pick up at the IFormValidator level
     // rather
     // than each individual property.
     return null;
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Exemplo n.º 4
0
  protected void init(
      final RepresentationType representationType,
      final Where where,
      final String urlUnencodedQueryString) {
    if (!IsisContext.inSession()) {
      throw RestfulObjectsApplicationException.create(HttpStatusCode.UNAUTHORIZED);
    }
    if (getAuthenticationSession() == null) {
      throw RestfulObjectsApplicationException.create(HttpStatusCode.UNAUTHORIZED);
    }

    this.resourceContext =
        new ResourceContext(
            representationType,
            httpHeaders,
            providers,
            uriInfo,
            request,
            where,
            urlUnencodedQueryString,
            httpServletRequest,
            httpServletResponse,
            securityContext,
            getDeploymentType(),
            getConfiguration(),
            getServicesInjector(),
            getSpecificationLoader(),
            getAuthenticationSession(),
            getLocalization(),
            getPersistenceSession(),
            InteractionInitiatedBy.USER);
  }
Exemplo n.º 5
0
  @Override
  protected void installFixturesIfRequired() throws IsisSystemException {

    fixtureInstaller = obtainFixturesInstaller();
    if (isNoop(fixtureInstaller)) {
      return;
    }

    IsisContext.openSession(new InitialisationSession());
    fixtureInstaller.installFixtures();
    try {

      // only allow logon fixtures if not in production mode.
      if (!getDeploymentType().isProduction()) {
        logonFixture = fixtureInstaller.getLogonFixture();
      }
    } finally {
      IsisContext.closeSession();
    }
  }
Exemplo n.º 6
0
  private void changeObject(
      final RequestContext context,
      final ObjectAdapter object,
      final FormState editState,
      final List<ObjectAssociation> fields) {
    for (int i = 0; i < fields.size(); i++) {
      final FieldEditState field = editState.getField(fields.get(i).getId());
      if (field == null) {
        continue;
      }
      final String newEntry = field.getEntry();
      final ObjectAdapter originalValue = fields.get(i).get(object);
      final boolean isVisible =
          fields
              .get(i)
              .isVisible(IsisContext.getAuthenticationSession(), object, where)
              .isAllowed();
      final boolean isUsable =
          fields.get(i).isUsable(IsisContext.getAuthenticationSession(), object, where).isAllowed();
      final boolean bothEmpty = originalValue == null && newEntry.equals("");
      final boolean bothSame =
          newEntry.equals(originalValue == null ? "" : originalValue.titleString());
      if ((!isVisible || !isUsable) || bothEmpty || bothSame) {
        if (fields.get(i).getSpecification().getFacet(ParseableFacet.class) == null) {
          // REVIEW restores object to loader
          context.getMappedObject(newEntry);
        }
        continue;
      }

      if (fields.get(i).getSpecification().containsFacet(ParseableFacet.class)) {
        final ParseableFacet facet =
            fields.get(i).getSpecification().getFacet(ParseableFacet.class);
        Localization localization = IsisContext.getLocalization();
        final ObjectAdapter newValue = facet.parseTextEntry(originalValue, newEntry, localization);
        ((OneToOneAssociation) fields.get(i)).set(object, newValue);
      } else {
        ((OneToOneAssociation) fields.get(i)).set(object, field.getValue());
      }
    }
  }
Exemplo n.º 7
0
  public void setObjectAsString(final String enteredText) {
    // parse text to get adapter
    final ParseableFacet parseableFacet = getTypeOfSpecification().getFacet(ParseableFacet.class);
    if (parseableFacet == null) {
      throw new RuntimeException(
          "unable to parse string for " + getTypeOfSpecification().getFullIdentifier());
    }
    Localization localization = IsisContext.getLocalization();
    final ObjectAdapter adapter =
        parseableFacet.parseTextEntry(getObject(), enteredText, localization);

    setObject(adapter);
  }
Exemplo n.º 8
0
  @Before
  public void setUp() throws Exception {
    org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);

    configuration = new IsisConfigurationDefault();
    servicesList = Collections.emptyList();

    oidMarshaller = new OidMarshaller();

    context.checking(
        new Expectations() {
          {
            ignoring(mockSpecificationLoader);
            ignoring(mockPersistenceSessionFactory);

            one(mockUserProfileLoader).getProfile(with(any(AuthenticationSession.class)));
            will(returnValue(new UserProfile()));

            ignoring(mockTemplateImageLoader);
            ignoring(mockAuthenticationManager);
            ignoring(mockAuthorizationManager);
          }
        });

    final ViewFactory subviewSpec =
        new ViewFactory() {
          @Override
          public View createView(final Content content, final Axes axes, final int fieldNumber) {
            return new DummyView();
          }
        };

    final IsisSessionFactoryDefault sessionFactory =
        new IsisSessionFactoryDefault(
            DeploymentType.EXPLORATION,
            configuration,
            mockTemplateImageLoader,
            mockSpecificationLoader,
            mockAuthenticationManager,
            mockAuthorizationManager,
            mockUserProfileLoader,
            mockPersistenceSessionFactory,
            servicesList,
            oidMarshaller);

    IsisContext.setConfiguration(sessionFactory.getConfiguration());
    IsisContextStatic.createRelaxedInstance(sessionFactory);
    IsisContextStatic.openSession(new ExplorationSession());

    builder = new ActionFieldBuilder(subviewSpec);
  }
  @Override
  public ApplicationAdvice appliesTo(IModel<?> model) {
    if (!(model instanceof EntityCollectionModel)) {
      return ApplicationAdvice.DOES_NOT_APPLY;
    }

    EntityCollectionModel entityCollectionModel = (EntityCollectionModel) model;
    if (entityCollectionModel.hasSelectionHandler()) {
      return ApplicationAdvice.DOES_NOT_APPLY;
    }

    ObjectSpecification typeOfSpec = entityCollectionModel.getTypeOfSpecification();
    ObjectSpecification pieChartableSpec =
        IsisContext.getSpecificationLoader().loadSpecification(PieChartable.class);
    return appliesIf(typeOfSpec.isOfType(pieChartableSpec));
  }
  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();
  }
  @Override
  protected void loadCollectionIntoList(
      final DatabaseConnector connector,
      final ObjectAdapter parent,
      final String table,
      final ObjectSpecification specification,
      final IdMappingAbstract idMappingAbstract,
      final Map<ObjectAssociation, FieldMapping> fieldMappingByField,
      final VersionMapping versionMapping,
      final List<ObjectAdapter> list) {
    LOG.debug("Loading polymorphic list");

    final StringBuffer sql = new StringBuffer();
    sql.append("select ");
    super.getIdMapping().appendColumnNames(sql);

    sql.append("," + getForeignKeyName());
    sql.append("," + classColumnName);
    sql.append("," + itemIdColumnName);

    sql.append(" from ");
    sql.append(table);
    sql.append(" where ");
    appendCollectionWhereValues(connector, parent, sql);

    final Results rs = connector.select(sql.toString());

    final SpecificationLoaderSpi reflector = IsisContext.getSpecificationLoader();
    final JdbcPolymorphicObjectReferenceMapping idMapping =
        (JdbcPolymorphicObjectReferenceMapping) idMappingAbstract;

    while (rs.next()) {
      final ObjectSpecification itemSpecification =
          reflector.loadSpecification(rs.getString(classColumnName));
      idMapping.setObjectSpecification(itemSpecification);

      // Load new recordSet for the actual class
      final ObjectMapping itemMapper = objectMappingLookup.getMapping(itemSpecification, connector);
      final TypedOid oid = idMapping.recreateOid(rs, itemSpecification);
      final ObjectAdapter loadedObject = itemMapper.getObject(connector, oid);

      LOG.debug("  element  " + loadedObject.getOid());

      list.add(loadedObject);
    }
    rs.close();
  }
Exemplo n.º 12
0
 @Override
 public String parseAndValidate(
     final ScalarModel scalarModel, final String proposedPojoAsStr) {
   final ObjectActionParameter parameter =
       scalarModel.getParameterMemento().getActionParameter();
   ParseableFacet parseableFacet = parameter.getFacet(ParseableFacet.class);
   if (parseableFacet == null) {
     parseableFacet = parameter.getSpecification().getFacet(ParseableFacet.class);
   }
   try {
     final ObjectAdapter parentAdapter =
         scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
     Localization localization = IsisContext.getLocalization();
     final String invalidReasonIfAny =
         parameter.isValid(parentAdapter, proposedPojoAsStr, localization);
     return invalidReasonIfAny;
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
  /** Lazily creates an {@link AuthenticationManager} that will authenticate all requests. */
  private AuthenticationManager anonymousAuthenticationManager() {
    if (authenticationManager == null) {
      final IsisConfiguration configuration = IsisContext.getConfiguration();
      final AuthenticationManagerStandard authenticationManager =
          new AuthenticationManagerStandard(configuration);
      authenticationManager.addAuthenticator(
          new AuthenticatorAbstract(configuration) {
            @Override
            public boolean isValid(final AuthenticationRequest request) {
              return true;
            }

            @Override
            public boolean canAuthenticate(
                final Class<? extends AuthenticationRequest> authenticationRequestClass) {
              return true;
            }
          });
      authenticationManager.init();
      this.authenticationManager = authenticationManager;
    }
    return authenticationManager;
  }
Exemplo n.º 14
0
 protected SpecificationLoaderSpi getSpecificationLoader() {
   return IsisContext.getSpecificationLoader();
 }
Exemplo n.º 15
0
 protected AuthenticationManager getAuthenticationManager() {
   return IsisContext.getAuthenticationManager();
 }
Exemplo n.º 16
0
 protected AuthenticationSession getAuthenticationSession() {
   return IsisContext.getAuthenticationSession();
 }
Exemplo n.º 17
0
 protected ServicesInjector getServicesInjector() {
   return IsisContext.getSessionFactory().getServicesInjector();
 }
Exemplo n.º 18
0
 protected IsisConfiguration getConfiguration() {
   return IsisContext.getConfiguration();
 }
Exemplo n.º 19
0
 protected IsisSessionFactory getIsisSessionFactory() {
   return IsisContext.getSessionFactory();
 }
Exemplo n.º 20
0
 protected OidMarshaller getOidMarshaller() {
   return IsisContext.getOidMarshaller();
 }
Exemplo n.º 21
0
 protected List<ObjectAdapter> getServiceAdapters() {
   return IsisContext.getPersistenceSession().getServices();
 }
Exemplo n.º 22
0
 public AdapterManager getAdapterManager() {
   return IsisContext.getPersistenceSession().getAdapterManager();
 }
Exemplo n.º 23
0
 @Override
 public Persistor getPersistenceSession() {
   return IsisContext.getPersistenceSession();
 }
Exemplo n.º 24
0
 protected ServicesInjector getServicesInjector() {
   return IsisContext.getPersistenceSession().getServicesInjector();
 }
Exemplo n.º 25
0
 protected PersistenceSession getPersistenceSession() {
   return IsisContext.getPersistenceSession();
 }
 private static PersistenceSession getPersistenceSession() {
   return IsisContext.getPersistenceSession();
 }
Exemplo n.º 27
0
 protected Localization getLocalization() {
   return IsisContext.getLocalization();
 }
Exemplo n.º 28
0
 protected DeploymentType getDeploymentType() {
   return IsisContext.getDeploymentType();
 }
Exemplo n.º 29
0
 public IsisContext getIsisContext() {
   return IsisContext.getInstance();
 }
 @Override
 public AuthenticationSession getAuthenticationSession() {
   return IsisContext.getAuthenticationSession();
 }