Source Code Cross Referenced for AbstractUser.java in  » Net » DrFTPD » org » drftpd » usermanager » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » DrFTPD » org.drftpd.usermanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * This file is part of DrFTPD, Distributed FTP Daemon.
0003:         *
0004:         * DrFTPD is free software; you can redistribute it and/or modify it under the
0005:         * terms of the GNU General Public License as published by the Free Software
0006:         * Foundation; either version 2 of the License, or (at your option) any later
0007:         * version.
0008:         *
0009:         * DrFTPD is distributed in the hope that it will be useful, but WITHOUT ANY
0010:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
0011:         * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
0012:         *
0013:         * You should have received a copy of the GNU General Public License along with
0014:         * DrFTPD; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
0015:         * Suite 330, Boston, MA 02111-1307 USA
0016:         */
0017:        package org.drftpd.usermanager;
0018:
0019:        import java.util.ArrayList;
0020:        import java.util.Calendar;
0021:        import java.util.Date;
0022:        import java.util.Iterator;
0023:        import java.util.List;
0024:
0025:        import net.sf.drftpd.DuplicateElementException;
0026:        import net.sf.drftpd.event.UserEvent;
0027:        import net.sf.drftpd.util.CalendarUtils;
0028:
0029:        import org.apache.log4j.Logger;
0030:        import org.drftpd.Bytes;
0031:        import org.drftpd.GlobalContext;
0032:        import org.drftpd.commands.UserManagement;
0033:        import org.drftpd.dynamicdata.Key;
0034:        import org.drftpd.dynamicdata.KeyedMap;
0035:        import org.drftpd.plugins.Trial;
0036:
0037:        /**
0038:         * Implements basic functionality for the User interface.
0039:         *
0040:         * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya </a>
0041:         * @author mog
0042:         * @version $Id: AbstractUser.java 1562 2007-01-05 12:37:07Z zubov $
0043:         */
0044:        public abstract class AbstractUser extends User {
0045:            private static final Logger logger = Logger
0046:                    .getLogger(AbstractUser.class);
0047:            public static final int P_ALL = 0;
0048:            public static final int P_DAY = 3;
0049:            public static final int P_MAX = 3;
0050:            public static final int P_MONTH = 1;
0051:            public static final int P_SIZE = 4;
0052:            public static final int P_WEEK = 2;
0053:
0054:            public static void checkValidGroupName(String group) {
0055:                if ((group.indexOf(' ') != -1) || (group.indexOf(';') != -1)) {
0056:                    throw new IllegalArgumentException(
0057:                            "Groups cannot contain space or other illegal characters");
0058:                }
0059:            }
0060:
0061:            private long _credits;
0062:            protected KeyedMap<Key, Object> _data = new KeyedMap<Key, Object>();
0063:
0064:            private long[] _downloadedBytes = new long[P_SIZE];
0065:
0066:            //private int _downloadedFiles, _downloadedFiles[P_DAY],
0067:            // _downloadedFiles[P_MONTH], _downloadedFiles[P_WEEK];
0068:            private int[] _downloadedFiles = new int[P_SIZE];
0069:            private long[] _downloadedMilliSeconds = new long[P_SIZE];
0070:
0071:            //protected long _downloadedMilliSeconds,
0072:            // _downloadedMilliSeconds[P_DAY],_downloadedMilliSeconds[P_MONTH],_downloadedMilliSeconds[P_WEEK];
0073:            private String _group = "nogroup";
0074:            private ArrayList<String> _groups = new ArrayList<String>();
0075:            private HostMaskCollection _hostMasks = new HostMaskCollection();
0076:            private int _idleTime = 0; // no limit
0077:
0078:            //private long _lastNuked;
0079:
0080:            /**
0081:             * Protected for DummyUser b/c TrialTest
0082:             */
0083:            protected long _lastReset;
0084:
0085:            //private long _nukedBytes;
0086:            //private int _racesLost;
0087:            //private int _racesParticipated;
0088:            //private int _racesWon;
0089:            //private float _ratio = 3.0F;
0090:            //private int _requests;
0091:            //private int _requestsFilled;
0092:
0093:            /*
0094:             * Protected b/c of DummyUser which needs to set it for TrialTest
0095:             */
0096:            protected long[] _uploadedBytes = new long[P_SIZE];
0097:
0098:            //protected long _uploadedBytes;
0099:            //protected long _uploadedBytes[P_DAY];
0100:            //protected long _uploadedBytes[P_MONTH];
0101:            //protected long _uploadedBytes[P_WEEK];
0102:            private int[] _uploadedFiles = new int[P_SIZE];
0103:
0104:            //private long _uploadedMilliSeconds;
0105:            //private long _uploadedMilliSeconds[P_DAY];
0106:            //private long _uploadedMilliSeconds[P_MONTH];
0107:            //private long _uploadedMilliSeconds[P_WEEK];
0108:            private long[] _uploadedMilliSeconds = new long[P_SIZE];
0109:
0110:            //    private int _uploadedFiles;
0111:            //    private int _uploadedFiles[P_DAY];
0112:            //    private int _uploadedFiles[P_MONTH];
0113:            //    private int _uploadedFiles[P_WEEK];
0114:            private String _username;
0115:
0116:            public AbstractUser(String username) {
0117:                _username = username;
0118:                _data.setObject(UserManagement.CREATED, new Date(System
0119:                        .currentTimeMillis()));
0120:                _data.setObject(UserManagement.TAGLINE, "no tagline");
0121:            }
0122:
0123:            public void addAllMasks(HostMaskCollection hostMaskCollection) {
0124:                getHostMaskCollection().addAllMasks(hostMaskCollection);
0125:            }
0126:
0127:            public void addIPMask(String mask) throws DuplicateElementException {
0128:                getHostMaskCollection().addMask(mask);
0129:            }
0130:
0131:            //    public void addRacesLost() {
0132:            //        _racesLost++;
0133:            //    }
0134:            //
0135:            //    public void addRacesParticipated() {
0136:            //        _racesParticipated++;
0137:            //    }
0138:            //
0139:            //    public void addRacesWon() {
0140:            //        _racesWon++;
0141:            //    }
0142:            //
0143:            //    public void addRequests() {
0144:            //        _requests++;
0145:            //    }
0146:            //
0147:            //    public void addRequestsFilled() {
0148:            //        _requestsFilled++;
0149:            //    }
0150:            public void addSecondaryGroup(String group)
0151:                    throws DuplicateElementException {
0152:                if (_groups.contains(group)) {
0153:                    throw new DuplicateElementException(
0154:                            "User is already a member of that group");
0155:                }
0156:
0157:                checkValidGroupName(group);
0158:                _groups.add(group);
0159:            }
0160:
0161:            /*
0162:             * public boolean checkIP(String[] masks, boolean useIdent) { Perl5Matcher m =
0163:             * new Perl5Matcher();
0164:             *
0165:             * for (Iterator e2 = ipMasks.iterator(); e2.hasNext();) { String mask =
0166:             * (String) e2.next();
0167:             *
0168:             * if (!useIdent) { mask = mask.substring(mask.indexOf('@') + 1);
0169:             *
0170:             * for (int i = 0; i < masks.length; i++) { masks[i] =
0171:             * masks[i].substring(masks[i].indexOf('@') + 1); } }
0172:             *
0173:             * Pattern p;
0174:             *
0175:             * try { p = new GlobCompiler().compile(mask); } catch
0176:             * (MalformedPatternException ex) { ex.printStackTrace();
0177:             *
0178:             * return false; }
0179:             *
0180:             * for (int i = 0; i < masks.length; i++) { if (m.matches(masks[i], p)) {
0181:             * return true; } } }
0182:             *
0183:             * return false; }
0184:             */
0185:            public boolean equals(Object obj) {
0186:                return (obj instanceof  User) ? ((User) obj).getName().equals(
0187:                        getName()) : false;
0188:            }
0189:
0190:            /**
0191:             * To avoid casting to AbstractUserManager
0192:             */
0193:            public abstract AbstractUserManager getAbstractUserManager();
0194:
0195:            public long getCredits() {
0196:                return _credits;
0197:            }
0198:
0199:            public long getDownloadedBytes() {
0200:                return _downloadedBytes[P_ALL];
0201:            }
0202:
0203:            public long getDownloadedBytesDay() {
0204:                return _downloadedBytes[P_DAY];
0205:            }
0206:
0207:            public long getDownloadedBytesForTrialPeriod(int period) {
0208:                switch (period) {
0209:                case Trial.PERIOD_DAILY:
0210:                    return _downloadedBytes[P_DAY];
0211:
0212:                case Trial.PERIOD_MONTHLY:
0213:                    return _downloadedBytes[P_MONTH];
0214:
0215:                case Trial.PERIOD_WEEKLY:
0216:                    return _downloadedBytes[P_WEEK];
0217:
0218:                case Trial.PERIOD_ALL:
0219:                    return _downloadedBytes[P_ALL];
0220:                }
0221:
0222:                throw new RuntimeException();
0223:            }
0224:
0225:            public long getDownloadedBytesMonth() {
0226:                return _downloadedBytes[P_MONTH];
0227:            }
0228:
0229:            public long getDownloadedBytesWeek() {
0230:                return _downloadedBytes[P_WEEK];
0231:            }
0232:
0233:            public int getDownloadedFiles() {
0234:                return _downloadedFiles[P_ALL];
0235:            }
0236:
0237:            public int getDownloadedFilesDay() {
0238:                return _downloadedFiles[P_DAY];
0239:            }
0240:
0241:            public int getDownloadedFilesForTrialPeriod(int period) {
0242:                switch (period) {
0243:                case Trial.PERIOD_DAILY:
0244:                    return _downloadedFiles[P_DAY];
0245:
0246:                case Trial.PERIOD_MONTHLY:
0247:                    return _downloadedFiles[P_MONTH];
0248:
0249:                case Trial.PERIOD_WEEKLY:
0250:                    return _downloadedFiles[P_WEEK];
0251:
0252:                case Trial.PERIOD_ALL:
0253:                    return _downloadedFiles[P_ALL];
0254:                }
0255:
0256:                throw new RuntimeException();
0257:            }
0258:
0259:            public int getDownloadedFilesMonth() {
0260:                return _downloadedFiles[P_MONTH];
0261:            }
0262:
0263:            public int getDownloadedFilesWeek() {
0264:                return _downloadedFiles[P_WEEK];
0265:            }
0266:
0267:            public long getDownloadedMillisecondsWeek() {
0268:                return _downloadedMilliSeconds[P_WEEK];
0269:            }
0270:
0271:            public long getDownloadedTime() {
0272:                return _downloadedMilliSeconds[P_ALL];
0273:            }
0274:
0275:            public long getDownloadedTimeForTrialPeriod(int period) {
0276:                switch (period) {
0277:                case Trial.PERIOD_DAILY:
0278:                    return _downloadedMilliSeconds[P_DAY];
0279:
0280:                case Trial.PERIOD_MONTHLY:
0281:                    return _downloadedMilliSeconds[P_MONTH];
0282:
0283:                case Trial.PERIOD_WEEKLY:
0284:                    return _downloadedMilliSeconds[P_WEEK];
0285:
0286:                case Trial.PERIOD_ALL:
0287:                    return _downloadedMilliSeconds[P_ALL];
0288:                }
0289:
0290:                throw new RuntimeException();
0291:            }
0292:
0293:            public String getGroup() {
0294:                if (_group == null) {
0295:                    return "nogroup";
0296:                }
0297:
0298:                return _group;
0299:            }
0300:
0301:            public List getGroups() {
0302:                return _groups;
0303:            }
0304:
0305:            public void setGroups(List<String> groups) {
0306:                _groups = new ArrayList<String>(groups);
0307:            }
0308:
0309:            public void setHostMaskCollection(HostMaskCollection masks) {
0310:                _hostMasks = masks;
0311:            }
0312:
0313:            public HostMaskCollection getHostMaskCollection() {
0314:                return _hostMasks;
0315:            }
0316:
0317:            public int getIdleTime() {
0318:                return _idleTime;
0319:            }
0320:
0321:            public KeyedMap<Key, Object> getKeyedMap() {
0322:                return _data;
0323:            }
0324:
0325:            public void setKeyedMap(KeyedMap<Key, Object> data) {
0326:                _data = data;
0327:            }
0328:
0329:            public long getLastReset() {
0330:                return _lastReset;
0331:            }
0332:
0333:            public void setLastReset(long lastReset) {
0334:                _lastReset = lastReset;
0335:            }
0336:
0337:            //    public int getRequests() {
0338:            //        return _requests;
0339:            //    }
0340:            //
0341:            //    public int getRequestsFilled() {
0342:            //        return _requestsFilled;
0343:            //    }
0344:            public long getUploadedBytes() {
0345:                return _uploadedBytes[P_ALL];
0346:            }
0347:
0348:            public long getUploadedBytesDay() {
0349:                return _uploadedBytes[P_DAY];
0350:            }
0351:
0352:            public long getUploadedBytesForTrialPeriod(int period) {
0353:                switch (period) {
0354:                case Trial.PERIOD_DAILY:
0355:                    return _uploadedBytes[P_DAY];
0356:
0357:                case Trial.PERIOD_MONTHLY:
0358:                    return _uploadedBytes[P_MONTH];
0359:
0360:                case Trial.PERIOD_WEEKLY:
0361:                    return _uploadedBytes[P_WEEK];
0362:
0363:                case Trial.PERIOD_ALL:
0364:                    return _uploadedBytes[P_ALL];
0365:                }
0366:
0367:                throw new RuntimeException();
0368:            }
0369:
0370:            public long getUploadedBytesMonth() {
0371:                return _uploadedBytes[P_MONTH];
0372:            }
0373:
0374:            public long getUploadedBytesWeek() {
0375:                return _uploadedBytes[P_WEEK];
0376:            }
0377:
0378:            public int getUploadedFiles() {
0379:                return _uploadedFiles[P_ALL];
0380:            }
0381:
0382:            public int getUploadedFilesDay() {
0383:                return _uploadedFiles[P_DAY];
0384:            }
0385:
0386:            public int getUploadedFilesForTrialPeriod(int period) {
0387:                switch (period) {
0388:                case Trial.PERIOD_DAILY:
0389:                    return _uploadedFiles[P_DAY];
0390:
0391:                case Trial.PERIOD_MONTHLY:
0392:                    return _uploadedFiles[P_MONTH];
0393:
0394:                case Trial.PERIOD_WEEKLY:
0395:                    return _uploadedFiles[P_WEEK];
0396:
0397:                case Trial.PERIOD_ALL:
0398:                    return _uploadedFiles[P_ALL];
0399:                }
0400:
0401:                throw new RuntimeException();
0402:            }
0403:
0404:            public int getUploadedFilesMonth() {
0405:                return _uploadedFiles[P_MONTH];
0406:            }
0407:
0408:            public int getUploadedFilesWeek() {
0409:                return _uploadedFiles[P_WEEK];
0410:            }
0411:
0412:            public long getUploadedTime() {
0413:                return _uploadedMilliSeconds[P_ALL];
0414:            }
0415:
0416:            public long getUploadedTimeForTrialPeriod(int period) {
0417:                switch (period) {
0418:                case Trial.PERIOD_DAILY:
0419:
0420:                    //return _uploadedMilliSeconds[P_DAY];
0421:                    return _uploadedMilliSeconds[P_DAY];
0422:
0423:                case Trial.PERIOD_MONTHLY:
0424:                    return _uploadedMilliSeconds[P_MONTH];
0425:
0426:                case Trial.PERIOD_WEEKLY:
0427:                    return _uploadedMilliSeconds[P_WEEK];
0428:
0429:                case Trial.PERIOD_ALL:
0430:                    return _uploadedMilliSeconds[P_ALL];
0431:                }
0432:
0433:                throw new RuntimeException();
0434:            }
0435:
0436:            public String getName() {
0437:                return _username;
0438:            }
0439:
0440:            public int hashCode() {
0441:                return getName().hashCode();
0442:            }
0443:
0444:            public boolean isAdmin() {
0445:                return isMemberOf("siteop");
0446:            }
0447:
0448:            public boolean isDeleted() {
0449:                return isMemberOf("deleted");
0450:            }
0451:
0452:            public boolean isExempt() {
0453:                return isMemberOf("exempt");
0454:            }
0455:
0456:            public boolean isGroupAdmin() {
0457:                return isMemberOf("gadmin");
0458:            }
0459:
0460:            public boolean isMemberOf(String group) {
0461:                if (getGroup().equals(group)) {
0462:                    return true;
0463:                }
0464:
0465:                for (Iterator iter = getGroups().iterator(); iter.hasNext();) {
0466:                    if (group.equals(iter.next())) {
0467:                        return true;
0468:                    }
0469:                }
0470:
0471:                return false;
0472:            }
0473:
0474:            public boolean isNuker() {
0475:                return isMemberOf("nuke");
0476:            }
0477:
0478:            public void logout() {
0479:            }
0480:
0481:            public void removeIpMask(String mask) throws NoSuchFieldException {
0482:                if (!_hostMasks.removeMask(mask)) {
0483:                    throw new NoSuchFieldException("User has no such ip mask");
0484:                }
0485:            }
0486:
0487:            public void removeSecondaryGroup(String group)
0488:                    throws NoSuchFieldException {
0489:                if (!_groups.remove(group)) {
0490:                    throw new NoSuchFieldException(
0491:                            "User is not a member of that group");
0492:                }
0493:            }
0494:
0495:            public void rename(String username) throws UserExistsException,
0496:                    UserFileException {
0497:                getAbstractUserManager().rename(this , username); // throws ObjectExistsException
0498:                getAbstractUserManager().delete(this .getName());
0499:                _username = username;
0500:                commit(); // throws IOException
0501:            }
0502:
0503:            public void reset(GlobalContext gctx) throws UserFileException {
0504:                reset(gctx, Calendar.getInstance());
0505:            }
0506:
0507:            protected void reset(GlobalContext gctx, Calendar cal)
0508:                    throws UserFileException {
0509:                //ignore reset() if we are called from userfileconverter or the like
0510:                if (gctx == null) {
0511:                    return;
0512:                }
0513:
0514:                Date lastResetDate = new Date(_lastReset);
0515:                _lastReset = cal.getTimeInMillis();
0516:
0517:                //cal = Calendar.getInstance();
0518:                Calendar calTmp = (Calendar) cal.clone();
0519:                calTmp.add(Calendar.DAY_OF_MONTH, -1);
0520:                CalendarUtils.ceilAllLessThanDay(calTmp);
0521:
0522:                //has not been reset since midnight
0523:                if (lastResetDate.before(calTmp.getTime())) {
0524:                    resetDay(gctx, cal.getTime());
0525:
0526:                    //floorDayOfWeek could go into the previous month
0527:                    calTmp = (Calendar) cal.clone();
0528:
0529:                    //calTmp.add(Calendar.WEEK_OF_YEAR, 1);
0530:                    CalendarUtils.floorDayOfWeek(calTmp);
0531:
0532:                    if (lastResetDate.before(calTmp.getTime())) {
0533:                        resetWeek(gctx, calTmp.getTime());
0534:                    }
0535:
0536:                    CalendarUtils.floorDayOfMonth(cal);
0537:
0538:                    if (lastResetDate.before(cal.getTime())) {
0539:                        resetMonth(gctx, cal.getTime());
0540:                    }
0541:
0542:                    commit(); //throws UserFileException
0543:                }
0544:            }
0545:
0546:            private void resetDay(GlobalContext gctx, Date resetDate) {
0547:                gctx.dispatchFtpEvent(new UserEvent(this , "RESETDAY", resetDate
0548:                        .getTime()));
0549:                _downloadedFiles[P_DAY] = 0;
0550:                _uploadedFiles[P_DAY] = 0;
0551:                _downloadedMilliSeconds[P_DAY] = 0;
0552:                _uploadedMilliSeconds[P_DAY] = 0;
0553:                _downloadedBytes[P_DAY] = 0;
0554:                _uploadedBytes[P_DAY] = 0;
0555:                logger.info("Reset daily stats for " + getName());
0556:            }
0557:
0558:            private void resetMonth(GlobalContext gctx, Date resetDate) {
0559:                gctx.dispatchFtpEvent(new UserEvent(this , "RESETMONTH",
0560:                        resetDate.getTime()));
0561:                _downloadedFiles[P_MONTH] = 0;
0562:                _uploadedFiles[P_MONTH] = 0;
0563:                _downloadedMilliSeconds[P_MONTH] = 0;
0564:                _uploadedMilliSeconds[P_MONTH] = 0;
0565:                _downloadedBytes[P_MONTH] = 0;
0566:                _uploadedBytes[P_MONTH] = 0;
0567:                logger.info("Reset monthly stats for " + getName());
0568:            }
0569:
0570:            private void resetWeek(GlobalContext gctx, Date resetDate) {
0571:                logger
0572:                        .info("Reset weekly stats for " + getName() + "(was "
0573:                                + Bytes.formatBytes(_uploadedBytes[P_WEEK])
0574:                                + " UP and "
0575:                                + Bytes.formatBytes(_downloadedBytes[P_WEEK])
0576:                                + " DOWN");
0577:                gctx.dispatchFtpEvent(new UserEvent(this , "RESETWEEK",
0578:                        resetDate.getTime()));
0579:                _downloadedFiles[P_WEEK] = 0;
0580:                _uploadedFiles[P_WEEK] = 0;
0581:                _downloadedMilliSeconds[P_WEEK] = 0;
0582:                _uploadedMilliSeconds[P_WEEK] = 0;
0583:                _downloadedBytes[P_WEEK] = 0;
0584:                _uploadedBytes[P_WEEK] = 0;
0585:
0586:                if (getKeyedMap().getObjectLong(UserManagement.WKLY_ALLOTMENT) > 0) {
0587:                    setCredits(getKeyedMap().getObjectLong(
0588:                            UserManagement.WKLY_ALLOTMENT));
0589:                }
0590:            }
0591:
0592:            public void setCredits(long credits) {
0593:                _credits = credits;
0594:            }
0595:
0596:            public void setDeleted(boolean deleted) {
0597:                if (deleted) {
0598:                    try {
0599:                        addSecondaryGroup("deleted");
0600:                    } catch (DuplicateElementException e) {
0601:                    }
0602:                } else {
0603:                    try {
0604:                        removeSecondaryGroup("deleted");
0605:                    } catch (NoSuchFieldException e) {
0606:                    }
0607:                }
0608:            }
0609:
0610:            public void setDownloadedBytes(long bytes) {
0611:                _downloadedBytes[P_ALL] = bytes;
0612:            }
0613:
0614:            public void setDownloadedBytesDay(long bytes) {
0615:                _downloadedBytes[P_DAY] = bytes;
0616:            }
0617:
0618:            public void setDownloadedBytesForTrialPeriod(int period, long bytes) {
0619:                switch (period) {
0620:                case Trial.PERIOD_DAILY:
0621:                    _downloadedBytes[P_DAY] = bytes;
0622:
0623:                    return;
0624:
0625:                case Trial.PERIOD_MONTHLY:
0626:                    _downloadedBytes[P_MONTH] = bytes;
0627:
0628:                    return;
0629:
0630:                case Trial.PERIOD_WEEKLY:
0631:                    _downloadedBytes[P_WEEK] = bytes;
0632:
0633:                    return;
0634:
0635:                case Trial.PERIOD_ALL:
0636:                    _downloadedBytes[P_ALL] = bytes;
0637:
0638:                    return;
0639:                }
0640:
0641:                throw new RuntimeException();
0642:            }
0643:
0644:            public void setDownloadedBytesMonth(long bytes) {
0645:                _downloadedBytes[P_MONTH] = bytes;
0646:            }
0647:
0648:            public void setDownloadedBytesWeek(long bytes) {
0649:                _downloadedBytes[P_WEEK] = bytes;
0650:            }
0651:
0652:            public void setDownloadedFiles(int files) {
0653:                _downloadedFiles[P_ALL] = files;
0654:            }
0655:
0656:            public void setDownloadedFilesDay(int files) {
0657:                _downloadedFiles[P_DAY] = files;
0658:            }
0659:
0660:            public void setDownloadedFilesForTrialPeriod(int period, int files) {
0661:                switch (period) {
0662:                case Trial.PERIOD_DAILY:
0663:                    _downloadedFiles[P_DAY] = files;
0664:
0665:                    return;
0666:
0667:                case Trial.PERIOD_MONTHLY:
0668:                    _downloadedFiles[P_MONTH] = files;
0669:
0670:                    return;
0671:
0672:                case Trial.PERIOD_WEEKLY:
0673:                    _downloadedFiles[P_WEEK] = files;
0674:
0675:                    return;
0676:
0677:                case Trial.PERIOD_ALL:
0678:                    _downloadedFiles[P_ALL] = files;
0679:
0680:                    return;
0681:                }
0682:
0683:                throw new RuntimeException();
0684:            }
0685:
0686:            public void setDownloadedFilesMonth(int files) {
0687:                _downloadedFiles[P_MONTH] = files;
0688:            }
0689:
0690:            public void setDownloadedFilesWeek(int files) {
0691:                _downloadedFiles[P_WEEK] = files;
0692:            }
0693:
0694:            public void setDownloadedSeconds(int millis) {
0695:                _downloadedMilliSeconds[P_ALL] = millis;
0696:            }
0697:
0698:            public void setDownloadedSecondsDay(int millis) {
0699:                _downloadedMilliSeconds[P_DAY] = millis;
0700:            }
0701:
0702:            public void setDownloadedSecondsMonth(int millis) {
0703:                _downloadedMilliSeconds[P_MONTH] = millis;
0704:            }
0705:
0706:            public void setDownloadedSecondsWeek(int millis) {
0707:                _downloadedMilliSeconds[P_WEEK] = millis;
0708:            }
0709:
0710:            public void setDownloadedTime(long millis) {
0711:                _downloadedMilliSeconds[P_ALL] = millis;
0712:            }
0713:
0714:            public void setDownloadedTimeDay(long millis) {
0715:                _downloadedMilliSeconds[P_DAY] = millis;
0716:            }
0717:
0718:            public void setDownloadedTimeForTrialPeriod(int period, long millis) {
0719:                switch (period) {
0720:                case Trial.PERIOD_DAILY:
0721:                    _downloadedMilliSeconds[P_DAY] = millis;
0722:
0723:                    return;
0724:
0725:                case Trial.PERIOD_MONTHLY:
0726:                    _downloadedMilliSeconds[P_MONTH] = millis;
0727:
0728:                    return;
0729:
0730:                case Trial.PERIOD_WEEKLY:
0731:                    _downloadedMilliSeconds[P_WEEK] = millis;
0732:
0733:                    return;
0734:
0735:                case Trial.PERIOD_ALL:
0736:                    _downloadedMilliSeconds[P_ALL] = millis;
0737:
0738:                    return;
0739:                }
0740:
0741:                throw new RuntimeException();
0742:            }
0743:
0744:            public void setDownloadedTimeMonth(long millis) {
0745:                _downloadedMilliSeconds[P_MONTH] = millis;
0746:            }
0747:
0748:            public void setDownloadedTimeWeek(long millis) {
0749:                _downloadedMilliSeconds[P_WEEK] = millis;
0750:            }
0751:
0752:            public void setGroup(String g) {
0753:                checkValidGroupName(g);
0754:                _group = g;
0755:            }
0756:
0757:            public void setIdleTime(int idleTime) {
0758:                _idleTime = idleTime;
0759:            }
0760:
0761:            public void setUploadedBytes(long bytes) {
0762:                _uploadedBytes[P_ALL] = bytes;
0763:            }
0764:
0765:            public void setUploadedBytesDay(long bytes) {
0766:                _uploadedBytes[P_DAY] = bytes;
0767:            }
0768:
0769:            public void setUploadedBytesForTrialPeriod(int period, long bytes) {
0770:                switch (period) {
0771:                case Trial.PERIOD_DAILY:
0772:                    _uploadedBytes[P_DAY] = bytes;
0773:
0774:                    return;
0775:
0776:                case Trial.PERIOD_MONTHLY:
0777:                    _uploadedBytes[P_MONTH] = bytes;
0778:
0779:                    return;
0780:
0781:                case Trial.PERIOD_WEEKLY:
0782:                    _uploadedBytes[P_WEEK] = bytes;
0783:
0784:                    return;
0785:
0786:                case Trial.PERIOD_ALL:
0787:                    _uploadedBytes[P_ALL] = bytes;
0788:
0789:                    return;
0790:                }
0791:
0792:                throw new RuntimeException();
0793:            }
0794:
0795:            public void setUploadedBytesMonth(long bytes) {
0796:                _uploadedBytes[P_MONTH] = bytes;
0797:            }
0798:
0799:            public void setUploadedBytesWeek(long bytes) {
0800:                _uploadedBytes[P_WEEK] = bytes;
0801:            }
0802:
0803:            public void setUploadedFiles(int files) {
0804:                _uploadedFiles[P_ALL] = files;
0805:            }
0806:
0807:            public void setUploadedFilesDay(int files) {
0808:                _uploadedFiles[P_DAY] = files;
0809:            }
0810:
0811:            public void setUploadedFilesForTrialPeriod(int period, int files) {
0812:                switch (period) {
0813:                case Trial.PERIOD_DAILY:
0814:                    _uploadedFiles[P_DAY] = files;
0815:
0816:                    return;
0817:
0818:                case Trial.PERIOD_MONTHLY:
0819:                    _uploadedFiles[P_MONTH] = files;
0820:
0821:                    return;
0822:
0823:                case Trial.PERIOD_WEEKLY:
0824:                    _uploadedFiles[P_WEEK] = files;
0825:
0826:                    return;
0827:
0828:                case Trial.PERIOD_ALL:
0829:                    _uploadedFiles[P_ALL] = files;
0830:
0831:                    return;
0832:                }
0833:
0834:                throw new RuntimeException();
0835:            }
0836:
0837:            public void setUploadedFilesMonth(int files) {
0838:                _uploadedFiles[P_MONTH] = files;
0839:            }
0840:
0841:            public void setUploadedFilesWeek(int files) {
0842:                _uploadedFiles[P_WEEK] = files;
0843:            }
0844:
0845:            public void setUploadedTime(int millis) {
0846:                _uploadedMilliSeconds[P_ALL] = millis;
0847:            }
0848:
0849:            public void setUploadedTime(long millis) {
0850:                _uploadedMilliSeconds[P_ALL] = millis;
0851:            }
0852:
0853:            public void setUploadedTimeDay(int millis) {
0854:                _uploadedMilliSeconds[P_DAY] = millis;
0855:            }
0856:
0857:            public void setUploadedTimeDay(long millis) {
0858:                _uploadedMilliSeconds[P_DAY] = millis;
0859:            }
0860:
0861:            public void setUploadedTimeForTrialPeriod(int period, long millis) {
0862:                switch (period) {
0863:                case Trial.PERIOD_DAILY:
0864:                    _uploadedMilliSeconds[P_DAY] = millis;
0865:
0866:                    return;
0867:
0868:                case Trial.PERIOD_MONTHLY:
0869:                    _uploadedMilliSeconds[P_MONTH] = millis;
0870:
0871:                    return;
0872:
0873:                case Trial.PERIOD_WEEKLY:
0874:                    _uploadedMilliSeconds[P_WEEK] = millis;
0875:
0876:                    return;
0877:
0878:                case Trial.PERIOD_ALL:
0879:                    _uploadedMilliSeconds[P_ALL] = millis;
0880:
0881:                    return;
0882:                }
0883:
0884:                throw new RuntimeException();
0885:            }
0886:
0887:            public void setUploadedTimeMonth(int millis) {
0888:                _uploadedMilliSeconds[P_MONTH] = millis;
0889:            }
0890:
0891:            public void setUploadedTimeMonth(long millis) {
0892:                _uploadedMilliSeconds[P_MONTH] = millis;
0893:            }
0894:
0895:            public void setUploadedTimeWeek(int millis) {
0896:                _uploadedMilliSeconds[P_WEEK] = millis;
0897:            }
0898:
0899:            public void setUploadedTimeWeek(long millis) {
0900:                _uploadedMilliSeconds[P_WEEK] = millis;
0901:            }
0902:
0903:            public void toggleGroup(String string) {
0904:                if (isMemberOf(string)) {
0905:                    try {
0906:                        removeSecondaryGroup(string);
0907:                    } catch (NoSuchFieldException e) {
0908:                        logger.error("isMemberOf() said we were in the group",
0909:                                e);
0910:                    }
0911:                } else {
0912:                    try {
0913:                        addSecondaryGroup(string);
0914:                    } catch (DuplicateElementException e) {
0915:                        logger.error(
0916:                                "isMemberOf() said we weren't in the group", e);
0917:                    }
0918:                }
0919:            }
0920:
0921:            public String toString() {
0922:                return _username;
0923:            }
0924:
0925:            public void updateCredits(long credits) {
0926:                _credits += credits;
0927:            }
0928:
0929:            public void updateDownloadedBytes(long bytes) {
0930:                _downloadedBytes[P_ALL] += bytes;
0931:                _downloadedBytes[P_DAY] += bytes;
0932:                _downloadedBytes[P_WEEK] += bytes;
0933:                _downloadedBytes[P_MONTH] += bytes;
0934:            }
0935:
0936:            public void updateDownloadedFiles(int i) {
0937:                _downloadedFiles[P_ALL] += i;
0938:                _downloadedFiles[P_DAY] += i;
0939:                _downloadedFiles[P_WEEK] += i;
0940:                _downloadedFiles[P_MONTH] += i;
0941:            }
0942:
0943:            public void updateDownloadedTime(long millis) {
0944:                _downloadedMilliSeconds[P_ALL] += millis;
0945:                _downloadedMilliSeconds[P_DAY] += millis;
0946:                _downloadedMilliSeconds[P_WEEK] += millis;
0947:                _downloadedMilliSeconds[P_MONTH] += millis;
0948:            }
0949:
0950:            /**
0951:             * Hit user - update last access time
0952:             */
0953:            public void updateLastAccessTime() {
0954:                _data.setObject(UserManagement.LASTSEEN, new Date(System
0955:                        .currentTimeMillis()));
0956:            }
0957:
0958:            //    public void updateNukedBytes(long bytes) {
0959:            //        _nukedBytes += bytes;
0960:            //    }
0961:            //
0962:            //    public void updateTimesNuked(int timesNuked) {
0963:            //        _timesNuked += timesNuked;
0964:            //    }
0965:            public void updateUploadedBytes(long bytes) {
0966:                _uploadedBytes[P_ALL] += bytes;
0967:                _uploadedBytes[P_DAY] += bytes;
0968:                _uploadedBytes[P_WEEK] += bytes;
0969:                _uploadedBytes[P_MONTH] += bytes;
0970:            }
0971:
0972:            public void updateUploadedFiles(int i) {
0973:                _uploadedFiles[P_ALL] += i;
0974:                _uploadedFiles[P_DAY] += i;
0975:                _uploadedFiles[P_WEEK] += i;
0976:                _uploadedFiles[P_MONTH] += i;
0977:            }
0978:
0979:            public void updateUploadedTime(long millis) {
0980:                _uploadedMilliSeconds[P_ALL] += millis;
0981:                _uploadedMilliSeconds[P_DAY] += millis;
0982:                _uploadedMilliSeconds[P_WEEK] += millis;
0983:                _uploadedMilliSeconds[P_MONTH] += millis;
0984:            }
0985:
0986:            public int getMaxSimUp() {
0987:                return getKeyedMap().getObjectInt(UserManagement.MAXSIMUP);
0988:            }
0989:
0990:            public void setMaxSimUp(int maxSimUp) {
0991:                getKeyedMap().setObject(UserManagement.MAXSIMUP, maxSimUp);
0992:            }
0993:
0994:            public float getMinRatio() {
0995:                return getKeyedMap().containsKey(UserManagement.MINRATIO) ? getKeyedMap()
0996:                        .getObjectFloat(UserManagement.MINRATIO)
0997:                        : 3F;
0998:            }
0999:
1000:            public void setMinRatio(float minRatio) {
1001:                getKeyedMap().setObject(UserManagement.MINRATIO, minRatio);
1002:            }
1003:
1004:            public float getMaxRatio() {
1005:                return getKeyedMap().containsKey(UserManagement.MAXRATIO) ? getKeyedMap()
1006:                        .getObjectFloat(UserManagement.MAXRATIO)
1007:                        : 3F;
1008:            }
1009:
1010:            public void setMaxRatio(float maxRatio) {
1011:                getKeyedMap().setObject(UserManagement.MAXRATIO, maxRatio);
1012:            }
1013:
1014:            public int getMaxSimDown() {
1015:                return getKeyedMap().getObjectInt(UserManagement.MAXSIMDN);
1016:            }
1017:
1018:            public void setMaxSimDown(int maxSimDown) {
1019:                getKeyedMap().setObject(UserManagement.MAXSIMDN, maxSimDown);
1020:            }
1021:
1022:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.