Package org.dspace.eperson

Examples of org.dspace.eperson.EPerson


     * @throws Exception
     */
    public static void createDownloadableExport(DSpaceObject dso,
            Context context, boolean migrate) throws Exception
    {
        EPerson eperson = context.getCurrentUser();
        ArrayList<DSpaceObject> list = new ArrayList<DSpaceObject>(1);
        list.add(dso);
        processDownloadableExport(list, context, eperson == null ? null
                : eperson.getEmail(), migrate);
    }
View Full Code Here


     * @throws Exception
     */
    public static void createDownloadableExport(List<DSpaceObject> dsObjects,
            Context context, boolean migrate) throws Exception
    {
        EPerson eperson = context.getCurrentUser();
        processDownloadableExport(dsObjects, context, eperson == null ? null
                : eperson.getEmail(), migrate);
    }
View Full Code Here

     * @throws Exception
     */
    private static void processDownloadableExport(List<DSpaceObject> dsObjects,
            Context context, final String additionalEmail, boolean toMigrate) throws Exception
    {
        final EPerson eperson = context.getCurrentUser();
        final boolean migrate = toMigrate;

        // before we create a new export archive lets delete the 'expired'
        // archives
        deleteOldExportArchives(eperson.getID());

        // keep track of the commulative size of all bitstreams in each of the
        // items
        // it will be checked against the config file entry
        float size = 0;
        final ArrayList<Integer> items = new ArrayList<Integer>();
        for (DSpaceObject dso : dsObjects)
        {
            if (dso.getType() == Constants.COMMUNITY)
            {
                Community community = (Community) dso;
                // get all the collections in the community
                Collection[] collections = community.getCollections();
                for (Collection collection : collections)
                {
                    // get all the items in each collection
                    ItemIterator iitems = collection.getItems();
                    try
                    {
                        while (iitems.hasNext())
                        {
                            Item item = iitems.next();
                            // get all the bundles in the item
                            Bundle[] bundles = item.getBundles();
                            for (Bundle bundle : bundles)
                            {
                                // get all the bitstreams in each bundle
                                Bitstream[] bitstreams = bundle.getBitstreams();
                                for (Bitstream bit : bitstreams)
                                {
                                    // add up the size
                                    size += bit.getSize();
                                }
                            }
                            items.add(item.getID());
                        }
                    }
                    finally
                    {
                        if (iitems != null)
                            iitems.close();
                    }
                }
            }
            else if (dso.getType() == Constants.COLLECTION)
            {
                Collection collection = (Collection) dso;
                // get all the items in the collection
                ItemIterator iitems = collection.getItems();
                try
                {
                    while (iitems.hasNext())
                    {
                        Item item = iitems.next();
                        // get all thebundles in the item
                        Bundle[] bundles = item.getBundles();
                        for (Bundle bundle : bundles)
                        {
                            // get all the bitstreams in the bundle
                            Bitstream[] bitstreams = bundle.getBitstreams();
                            for (Bitstream bit : bitstreams)
                            {
                                // add up the size
                                size += bit.getSize();
                            }
                        }
                        items.add(item.getID());
                    }
                }
                finally
                {
                    if (iitems != null)
                        iitems.close();
                }
            }
            else if (dso.getType() == Constants.ITEM)
            {
                Item item = (Item) dso;
                // get all the bundles in the item
                Bundle[] bundles = item.getBundles();
                for (Bundle bundle : bundles)
                {
                    // get all the bitstreams in the bundle
                    Bitstream[] bitstreams = bundle.getBitstreams();
                    for (Bitstream bit : bitstreams)
                    {
                        // add up the size
                        size += bit.getSize();
                    }
                }
                items.add(item.getID());
            }
            else
            {
                // nothing to do just ignore this type of DSPaceObject
            }
        }

        // check the size of all the bitstreams against the configuration file
        // entry if it exists
        String megaBytes = ConfigurationManager
                .getProperty("org.dspace.app.itemexport.max.size");
        if (megaBytes != null)
        {
            float maxSize = 0;
            try
            {
                maxSize = Float.parseFloat(megaBytes);
            }
            catch (Exception e)
            {
                // ignore...configuration entry may not be present
            }

            if (maxSize > 0)
            {
                if (maxSize < (size / 1048576.00))
                { // a megabyte
                    throw new ItemExportException(ItemExportException.EXPORT_TOO_LARGE,
                                                  "The overall size of this export is too large.  Please contact your administrator for more information.");
                }
            }
        }

        // if we have any items to process then kick off annonymous thread
        if (items.size() > 0)
        {
            Thread go = new Thread()
            {
                public void run()
                {
                    Context context = null;
                    ItemIterator iitems = null;
                    try
                    {
                        // create a new dspace context
                        context = new Context();
                        // ignore auths
                        context.setIgnoreAuthorization(true);
                        iitems = new ItemIterator(context, items);

                        String fileName = assembleFileName("item", eperson,
                                new Date());
                        String workDir = getExportWorkDirectory()
                                + System.getProperty("file.separator")
                                + fileName;
                        String downloadDir = getExportDownloadDirectory(eperson
                                .getID());

                        File wkDir = new File(workDir);
                        if (!wkDir.exists())
                        {
View Full Code Here

    {
        try
        {
            Context context = ContextUtil.obtainContext(objectModel);

            EPerson eperson = context.getCurrentUser();

            if (eperson == null)
                // No one is authenticated.
                return false;
View Full Code Here

     *            the file name to check auths for
     * @return true if it is the same person false otherwise
     */
    public static boolean canDownload(Context context, String fileName)
    {
        EPerson eperson = context.getCurrentUser();
        if (eperson == null)
        {
            return false;
        }
        String strID = fileName.substring(fileName.lastIndexOf('_') + 1,
                fileName.lastIndexOf('.'));
        try
        {
            if (Integer.parseInt(strID) == eperson.getID())
            {
                return true;
            }
        }
        catch (Exception e)
View Full Code Here

                    return BAD_CREDENTIALS;
                }

                // And it's valid - try and get an e-person
                String email = getEmail(certs[0]);
                EPerson eperson = null;
                if (email != null)
                    eperson = EPerson.findByEmail(context, email);
                if (eperson == null)
                {
                    // Cert is valid, but no record.
                    if (email != null
                            && canSelfRegister(context, request, null))
                    {
                        // Register the new user automatically
                        log.info(LogManager.getHeader(context, "autoregister",
                                "from=x.509, email=" + email));

                        // TEMPORARILY turn off authorisation
                        context.setIgnoreAuthorization(true);
                        eperson = EPerson.create(context);
                        eperson.setEmail(email);
                        eperson.setCanLogIn(true);
                        AuthenticationManager.initEPerson(context, request,
                                eperson);
                        eperson.update();
                        context.commit();
                        context.setIgnoreAuthorization(false);
                        context.setCurrentUser(eperson);
                        setSpecialGroupsFlag(request, email);
                        return SUCCESS;
                    }
                    else
                    {
                        // No auto-registration for valid certs
                        log
                                .warn(LogManager
                                        .getHeader(context, "authenticate",
                                                "type=cert_but_no_record, cannot auto-register"));
                        return NO_SUCH_USER;
                    }
                }

                // make sure this is a login account
                else if (!eperson.canLogIn())
                {
                    log.warn(LogManager.getHeader(context, "authenticate",
                            "type=x509certificate, email=" + email
                                    + ", canLogIn=false, rejecting."));
                    return BAD_ARGS;
View Full Code Here

      System.out.println("Purging collection of all items and reseting last_harvested and harvest_message: " + collectionID);
      Collection collection = resolveCollection(collectionID);
    
      try
      {
        EPerson eperson = EPerson.findByEmail(context, email);
          context.setCurrentUser(eperson);
        context.turnOffAuthorisationSystem();
       
        ItemIterator it = collection.getAllItems();
        IndexBrowse ib = new IndexBrowse(context);
View Full Code Here

      se.printStackTrace();
    }
           
      try {
        // Harvest will not work for an anonymous user
          EPerson eperson = EPerson.findByEmail(context, email);
          System.out.println("Harvest started... ");
          context.setCurrentUser(eperson);
        harvester.runHarvest();
        context.complete();
      }
View Full Code Here

        // Skip out when no netid or password is given.
        if (netid == null || password == null)
          return BAD_ARGS;

        // Locate the eperson
        EPerson eperson = null;
        try
        {
            eperson = EPerson.findByNetid(context, netid.toLowerCase());
        }
        catch (SQLException e)
        {
        }
        boolean loggedIn = false;
        SpeakerToLDAP ldap = new SpeakerToLDAP(log);

        // if they entered a netid that matches an eperson
        if (eperson != null)
        {
            // e-mail address corresponds to active account
            if (eperson.getRequireCertificate())
                return CERT_REQUIRED;
            else if (!eperson.canLogIn())
                return BAD_ARGS;
            {
                if (ldap.ldapAuthenticate(netid, password, context))
                {
                    context.setCurrentUser(eperson = EPerson.findByNetid(context, netid.toLowerCase()));
                    log.info(LogManager
                        .getHeader(context, "authenticate", "type=ldap"));
                    return SUCCESS;
                }
                else
                   return BAD_CREDENTIALS;
            }
        }

        // the user does not already exist so try and authenticate them
        // with ldap and create an eperson for them
        else
        {
            if (ldap.ldapAuthenticate(netid, password, context))
            {
                // Register the new user automatically
                log.info(LogManager.getHeader(context,
                                "autoregister", "netid=" + netid));

                if ((ldap.ldapEmail!=null)&&(!ldap.ldapEmail.equals("")))
                {
                    try
                    {
                        eperson = EPerson.findByEmail(context, ldap.ldapEmail);
                      if (eperson!=null)
                      {
                          log.info(LogManager.getHeader(context,
                                  "type=ldap-login", "type=ldap_but_already_email"));
                          context.setIgnoreAuthorization(true);
                          eperson.setNetid(netid.toLowerCase());
                          eperson.update();
                          context.commit();
                          context.setIgnoreAuthorization(false);
                          context.setCurrentUser(eperson);
                          return SUCCESS;
                      }
                      else
                      {
                          if (canSelfRegister(context, request, netid))
                          {
                              // TEMPORARILY turn off authorisation
                              try
                              {
                                  context.setIgnoreAuthorization(true);
                                  eperson = EPerson.create(context);
                                  if ((ldap.ldapEmail!=null)&&(!ldap.ldapEmail.equals(""))) eperson.setEmail(ldap.ldapEmail);
                                  else eperson.setEmail(netid);
                                  if ((ldap.ldapGivenName!=null)&&(!ldap.ldapGivenName.equals(""))) eperson.setFirstName(ldap.ldapGivenName);
                                  if ((ldap.ldapSurname!=null)&&(!ldap.ldapSurname.equals(""))) eperson.setLastName(ldap.ldapSurname);
                                  if ((ldap.ldapPhone!=null)&&(!ldap.ldapPhone.equals(""))) eperson.setMetadata("phone", ldap.ldapPhone);
                                  eperson.setNetid(netid.toLowerCase());
                                  eperson.setCanLogIn(true);
                                  AuthenticationManager.initEPerson(context, request, eperson);
                                  eperson.update();
                                  context.commit();
                  context.setCurrentUser(eperson);
                }
                              catch (AuthorizeException e)
                              {
View Full Code Here

            throw new AuthorizeException(I18nUtil.getMessage("feedback.error.forbidden"));
        }

        // User email from context
        Context context = ContextUtil.obtainContext(objectModel);
        EPerson loggedin = context.getCurrentUser();
        String eperson = null;
        if (loggedin != null)
            eperson = loggedin.getEmail();

        if (page == null || page.equals(""))
        {
            page = fromPage;
        }
View Full Code Here

TOP

Related Classes of org.dspace.eperson.EPerson

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.