示例#1
0
    public static void insert(Application app) {

      final String adminGroupTitle = app.configuration().getString("htwplus.admin.group");
      final String adminMail = app.configuration().getString("htwplus.admin.mail");
      final String adminPassword = app.configuration().getString("htwplus.admin.pw");

      // Do some inital db stuff
      JPA.withTransaction(
          new play.libs.F.Callback0() {

            @Override
            public void invoke() throws Throwable {

              // create Admin account if none exists
              Account admin = Account.findByEmail(adminMail);
              if (admin == null) {
                admin = new Account();
                admin.email = adminMail;
                admin.firstname = "Admin";
                admin.lastname = "@HTWplus";
                admin.role = AccountRole.ADMIN;
                admin.avatar = "a1";
                admin.password = Component.md5(adminPassword);
                admin.create();
              }

              // create Admin group if none exists
              Group group = Group.findByTitle(adminGroupTitle);
              if (group == null && admin != null) {
                group = new Group();
                group.title = adminGroupTitle;
                group.groupType = GroupType.close;
                group.description = "for HTWplus Admins only";
                group.createWithGroupAccount(admin);
              }

              // create Feedback group if none exists
              Group feedbackGroup = Group.findByTitle("HTWplus Feedback");
              if (feedbackGroup == null && admin != null) {
                group = new Group();
                group.title = "HTWplus Feedback";
                group.groupType = GroupType.open;
                group.description =
                    "Du hast Wünsche, Ideen, Anregungen, Kritik oder Probleme mit der Seite? Hier kannst du es loswerden!";
                group.createWithGroupAccount(admin);
              }

              // Generate indexes
              FullTextEntityManager fullTextEntityManager =
                  Search.getFullTextEntityManager(JPA.em());
              try {
                fullTextEntityManager.createIndexer(Group.class, Account.class).startAndWait();

              } catch (InterruptedException e) {

                Logger.error(e.getMessage());
              }
            }
          });
    }
示例#2
0
  @Override
  public void onStart() {
    String accessKey = application.configuration().getString(AWS_ACCESS_KEY);
    String secretKey = application.configuration().getString(AWS_SECRET_KEY);
    s3Bucket = application.configuration().getString(AWS_S3_BUCKET);

    if ((accessKey != null) && (secretKey != null)) {
      AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
      amazonS3 = new AmazonS3Client(awsCredentials);
      amazonS3.createBucket(s3Bucket);
      Logger.info("Using S3 Bucket: " + s3Bucket);
    }
  }
 @Override
 public boolean enabled() {
   isEnabled =
       !"disabled".equals(application.configuration().getString(Constants.MORPHIA_PLUGIN_ENABLED));
   MorphiaLogger.warn(String.format("MorphiaPlugin is %s", isEnabled ? "enabled" : "disabled"));
   return isEnabled;
 }
示例#4
0
 @Provides
 Mongo create(final Application application) {
   try {
     return new Mongo(new MongoURI(application.configuration().getString("mongodb.uri")));
   } catch (UnknownHostException e) {
     addError(e);
     return null;
   }
 }
示例#5
0
  @Provides
  Datastore createDatastore(Mongo mongo, Morphia morphia, final Application application) {
    Datastore datastore =
        morphia.createDatastore(
            mongo,
            application.configuration().getString("mongodb.db"),
            application.configuration().getString("mongodb.username"),
            application.configuration().getString("mongodb.password").toCharArray());

    datastore.ensureIndexes();

    Logger.info(
        "Connected to MongoDB ["
            + mongo.debugString()
            + "] database ["
            + datastore.getDB().getName()
            + "]");
    return datastore;
  }
示例#6
0
  @Override
  public void onStart(Application app) {
    if (app.isDev()) {
      Logger.info("using development database: " + PlayJongo.getDatabase().getName());
    }

    if (app.isTest()) {
      Logger.info("using test database: " + PlayJongo.getDatabase().getName());
      Logger.info("playjongo.test-uri: " + app.configuration().getString("playjongo.test-uri", ""));
    }
  }
示例#7
0
 @Override
 public boolean enabled() {
   return (application.configuration().keys().contains(AWS_ACCESS_KEY)
       && application.configuration().keys().contains(AWS_SECRET_KEY)
       && application.configuration().keys().contains(AWS_S3_BUCKET));
 }
示例#8
0
 @Override
 public void onStart(Application app) {
   Util.configure(app.configuration());
   SitemapJob.startSitemapGenerator();
 }
示例#9
0
  @Override
  public void onStart() {
    Logger.debug("Spring Plugin Starting");

    String contextPath = app.configuration().getString(SPRING_CONTEXT_PATH);
    String namespaceAware = app.configuration().getString(SPRING_NAMESPACE_AWARE);
    String addPlayProperties = app.configuration().getString(SPRING_ADD_PLAY_PROPERTIES);

    URL url = null;
    if (contextPath != null) {
      Logger.debug("Loading application context: " + contextPath);
      url = app.classloader().getResource(contextPath);
    }
    if (url == null) {
      Logger.debug("Loading default application context: application-context.ml");
      url = app.classloader().getResource("application-context.xml");
    }
    if (url != null) {
      InputStream is = null;
      try {
        Logger.debug("Starting Spring application context from " + url.toExternalForm());
        applicationContext = new GenericApplicationContext();
        applicationContext.setClassLoader(Play.application().classloader());
        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext);
        if (!"false".equalsIgnoreCase(namespaceAware)) {
          Logger.debug("Application context is namespace aware");
          xmlReader.setNamespaceAware(true);
        } else {
          Logger.debug("Application context is NOT namespace aware");
        }
        xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);

        // Load Play Configuration
        if (!"false".equalsIgnoreCase(addPlayProperties)) {
          Logger.debug("Adding PropertyPlaceholderConfigurer with Play properties");

          // Convert play's configuration to plain old java properties
          Properties properties = new Properties();
          Set<String> keys = app.configuration().keys();
          for (String key : keys) {
            try {
              String value = app.configuration().getString(key);
              properties.setProperty(key, value);
            } catch (Throwable t) {
              // Some config items are complex, so we'll just skip those for now.
            }
          }

          PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
          configurer.setProperties(properties);
          applicationContext.addBeanFactoryPostProcessor(configurer);
        } else {
          Logger.debug("PropertyPlaceholderConfigurer with Play properties NOT added");
        }

        is = url.openStream();
        xmlReader.loadBeanDefinitions(new InputSource(is));
        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(app.classloader());
        try {
          applicationContext.refresh();
          // startDate = System.currentTimeMillis();
        } catch (BeanCreationException e) {
          Throwable ex = e.getCause();
          throw new RuntimeException("Unable to instantiate Spring application context", ex);
        } finally {
          Thread.currentThread().setContextClassLoader(originalClassLoader);
        }
      } catch (IOException e) {
        Logger.error("Can't load spring config file", e);
      } finally {
        if (is != null) {
          try {
            is.close();
          } catch (IOException e) {
            Logger.error("Can't close spring config file stream", e);
          }
        }
      }
    }
  }