⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 facadeimpl.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                this.modificationEvent = new ModificationEventImpl(storeEvents, removeEvents);
            } else {
                // refresh
                this.modificationEvent = new ModificationEventImpl();
            }

            Logger logger = getLogger().getChildLogger("trigger.allocation");
            AllocationChangeFinder trigger = new AllocationChangeFinder( logger, evt );
            allocationChangeEvents = (AllocationChangeEvent[]) trigger.getTriggerEvents() .toArray(new AllocationChangeEvent[0]);
        }

        public boolean hasFailed() {
            return bError;
        }

        public void execute() {
            run();
        }

        public void run() {
            long time = System.currentTimeMillis();
            Iterator it = listeners.iterator();

            while (it.hasNext()) {
                if (!operator.isConnected())
                    return;
                try {
                    Object listener = it.next();
                    if (getLogger().isDebugEnabled())
                        getLogger().debug("Notifing " + listener);
                    if ( listener instanceof ModificationListener) {
                        ((ModificationListener)listener).dataChanged(modificationEvent);
                    }
                    if ( listener instanceof AllocationChangeListener && allocationChangeEvents.length > 0) {
                        ((AllocationChangeListener)listener).changed( allocationChangeEvents );
                    }

                } catch (RaplaException ex) {
                    getLogger().error("update-exception",ex);
                    bError = true;
                } catch (Exception ex) {
                    getLogger().error("update-exception",ex);
                    bError = true;
                }
            }
            if (getLogger().isDebugEnabled() && !bError)
                getLogger().debug("GUI update took " + (System.currentTimeMillis()- time) +  " ms.");
            if (hasFailed())
                getLogger().error("There was an error while refreshing the displayed data. It could be different from the data stored. Restarting Rapla is recommended.");
        }
    };

    /** fires update event asynchronous.
    */
    protected void fireUpdateEvent(UpdateResult evt) {
    	if ( periodModel != null)
    	{
    		try {
				periodModel.update();
			} catch (RaplaException e) {
				getLogger().error( "Can't update Period Model", e );
			}
    	}
        Collection modificationListeners = getModificationListeners(false);
        Collection allocationChangeListeners = getAllocationChangeListeners( false );
        if (modificationListeners.size()>0 || allocationChangeListeners.size() > 0)
        {
            notifyQueue.enqueue(new UpdateCommand(modificationListeners,allocationChangeListeners, evt));
        }
        modificationListeners = getModificationListeners(true);
        allocationChangeListeners = getAllocationChangeListeners( true );
        if (modificationListeners.size()>0 || allocationChangeListeners.size() > 0)
        {
            javax.swing.SwingUtilities.invokeLater(new UpdateCommand(modificationListeners, allocationChangeListeners, evt));
        }
        if (getLogger().isDebugEnabled())
        {
            getLogger().debug("Update event fired");
        }
    }




    /******************************
     * Query-module               *
     ******************************/
    private Collection getVisibleAllocatables(ClassificationFilter[] filters) throws RaplaException {
        Collection allocatables = new ArrayList();
        synchronized (operator.getLock()) {
            allocatables.addAll(operator.getObjects(Allocatable.TYPE));
        }
        Iterator it = allocatables.iterator();
        while ( it.hasNext() ) {
            Allocatable allocatable = (Allocatable) it.next();
            if ( workingUser == null || workingUser.isAdmin())
                continue;
            if ( !allocatable.canRead( workingUser ) )
                it.remove();
        }

        removeFilteredClassifications( allocatables, filters);
        return allocatables;
    }

    private Collection getVisibleReservations(User user, Date start, Date end, ClassificationFilter[] filters) throws RaplaException {
        Collection reservations = new ArrayList();
        synchronized (operator.getLock()) {
            reservations.addAll(operator.getReservations(user,start, end));
        }
        removeFilteredClassifications( reservations, filters);
        Iterator it = reservations.iterator();
        while ( it.hasNext() ) {
            Reservation r = (Reservation) it.next();
            if ( workingUser == null || r.getOwner().equals( workingUser ) || workingUser.isAdmin())
                continue;
            Allocatable[] allocatables = r.getAllocatables();
            boolean oneVisibleAllocatable = false;
            for ( int i=0;i<allocatables.length;i++) {
                if (allocatables[i].canRead( workingUser )) {
                    oneVisibleAllocatable = true;
                    break;
                }
            }
            if ( !oneVisibleAllocatable)
                it.remove();
        }
        return reservations;
    }

    private void removeFilteredClassifications(Collection list, ClassificationFilter[] filters) {
        if ( filters == null || filters.length == 0)
            return;

        Iterator it = list.iterator();
        while ( it.hasNext() ) {
            Classification classification = ((Classifiable) it.next() ).getClassification();
            boolean found = false;
            for ( int i=0;i<filters.length;i++) {
                if ( filters[i].matches( classification ) ) {
                    found = true;
                    break;
                }
            }
            if ( !found )
                it.remove();
        }
    }

    public Allocatable[] getAllocatables() throws RaplaException {
        return getAllocatables(null);
    }

    public Allocatable[] getAllocatables(ClassificationFilter[] filters) throws RaplaException {
        return (Allocatable[]) getVisibleAllocatables(filters).toArray(Allocatable.ALLOCATABLE_ARRAY);
    }

    public Reservation[] getReservations(User user,Date start,Date end,ClassificationFilter[] filters) throws RaplaException {
        return (Reservation[]) getVisibleReservations( user, start, end, filters).toArray(Reservation.RESERVATION_ARRAY);
    }

    public boolean canExchangeAllocatables(Reservation reservation) {
        try {
            Allocatable[] all = getAllocatables( null );
            User user = getUser();
            for ( int i=0; i<all.length; i++) {
                if ( all[i].canModify( user ) ) {
                    return true;
                }
            }
        } catch (RaplaException ex) {
        }
        return false;
     }

    public Preferences getPreferences() throws RaplaException {
        return getPreferences(getUser());
    }

    public Preferences getPreferences(User user) throws RaplaException {
        synchronized (operator.getLock()) {
            return (Preferences) operator.getPreferences(user);
        }
    }

    public Category getSuperCategory() {
        synchronized (operator.getLock()) {
            return (Category)
                operator.getSuperCategory();
        }
    }

    public Category getUserGroupsCategory() throws RaplaException {
        Category userGroups = getSuperCategory().getCategory(Permission.GROUP_CATEGORY_KEY);
        if ( userGroups == null) {
            throw new RaplaException("No category '" + Permission.GROUP_CATEGORY_KEY + "' available");
        }
        return userGroups;
    }

    public Reservation[] getReservations(Allocatable[] allocatables, Date start, Date end) throws RaplaException {
            Collection reservations = getVisibleReservations( null, start, end , null);
            Collection allocatableSet = new HashSet( Arrays.asList( allocatables ) );
            Iterator it = reservations.iterator();
            while (it.hasNext()) {
                Reservation reservation = (Reservation) it.next();
                Allocatable[] reservedAllocatables = reservation.getAllocatables();
                boolean bFound = false;
                for (int i=0;i<reservedAllocatables.length;i++)
                {
                    if (allocatableSet.contains(reservedAllocatables[i]))
                        bFound = true;
                }
                if (!bFound)
                	it.remove();
            }
            return (Reservation[]) reservations.toArray(Reservation.RESERVATION_ARRAY);
    }

    public Period[] getPeriods() throws RaplaException {
        synchronized (operator.getLock()) {
            Period[] result = (Period[])
                operator.getObjects(Period.TYPE).toArray(Period.PERIOD_ARRAY);
            return result;
        }
    }

	public PeriodModel getPeriodModel() throws RaplaException {
		if ( periodModel == null) {
			periodModel = new PeriodModelImpl( this );
		}
		return periodModel;
	}


    public DynamicType[] getDynamicTypes(String classificationType) throws RaplaException {
        if ( classificationType == null) {
            synchronized (operator.getLock()) {
                return (DynamicType[]) operator.getObjects(DynamicType.TYPE).toArray(DynamicType.DYNAMICTYPE_ARRAY);
            }
        }
        ArrayList result = new ArrayList();
        synchronized (operator.getLock()) {
            Collection collection = operator.getObjects(DynamicType.TYPE);
            for (Iterator it = collection.iterator();it.hasNext();)
            {
                DynamicType type =(DynamicType) it.next();
                if ( classificationType.equals(type.getAnnotation(DynamicTypeAnnotations.KEY_CLASSIFICATION_TYPE) ) ) {
                    result.add( type );
                }
            }
        }
        return (DynamicType[]) result.toArray(DynamicType.DYNAMICTYPE_ARRAY);
    }

    public DynamicType getDynamicType(String elementKey) throws RaplaException {
        synchronized (operator.getLock()) {
            Collection collection = operator.getObjects(DynamicType.TYPE);
            for (Iterator it = collection.iterator();it.hasNext();)
            {
                DynamicType type = (DynamicType) it.next();
                if (type.getElementKey().equals(elementKey))
                    return type;
            }
        }
        throw new EntityNotFoundException("No dynamictype with elementKey " + elementKey);
    }

    public User[] getUsers() throws RaplaException {
        synchronized (operator.getLock()) {
            Set users = new TreeSet( new UserComparator( locale));
            users.addAll( operator.getObjects(User.TYPE));
            return (User[])users
               .toArray(User.USER_ARRAY);
        }
    }

    public User getUser(String username) throws RaplaException {
        synchronized (operator.getLock()) {
            User user = operator.getUser(username);
            if (user == null)
                throw new EntityNotFoundException("No User with username " + username);
            return user;
        }
    }

    public Conflict[] getConflicts(Reservation reservation) throws RaplaException {
        return conflictFinder.getConflicts( today(), reservation );
    }

    public Conflict [] getConflicts(Date startDate) throws RaplaException {
        return conflictFinder.getConflicts( startDate, (User) null );
    }

    public boolean hasPermissionToAllocate( Appointment appointment, Allocatable allocatable)  {
        if ( workingUser == null) {
            return true;
        }
        try {
            Reservation reservation =  appointment.getReservation();
            Reservation originalReservation;
            if ( !reservation.isPersistant())
            {
                try
                {
                    originalReservation= (Reservation) getPersistant( reservation );
                }
                catch (EntityNotFoundException ex)
                {
                    // is New
                    originalReservation = null;
                    return allocatable.canAllocate( workingUser, appointment.getStart(), appointment.getMaxEnd(), today());
                }
            } else {
                originalReservation = null;
            }
            return conflictFinder.hasPermissionToAllocate( workingUser, appointment, allocatable, originalReservation);
        } catch (RaplaException ex) {
            getLogger().error("Can't get permissions!", ex);
            return false;
        }
    }

    public Allocatable[] getAllocatableBindings(Appointment forAppointment) throws RaplaException {
        return (Allocatable[])conflictFinder.getAllocatableBindings( forAppointment ).toArray( Allocatable.ALLOCATABLE_ARRAY);
    }

    /******************************
     * Login - Module             *
     ******************************/
    public User getUser() throws RaplaException {
        if (this.workingUser == null) {
            throw new RaplaException("no user loged in");
        }
        return this.workingUser;
    }

    public boolean login(String username, char[] password) throws RaplaException {
        synchronized (operator.getLock()) {
            try {
                if (!operator.isConnected()) {
                    operator.connect(username,password);
                }


            } catch (RaplaSecurityException ex) {
                return false;
            } finally {
                // Clear password
                for (int i = 0;i<password.length;i++)
                    password[i]=0;
            }
            User user = operator.getUser(username);
            if (user != null) {
                this.workingUser = user;
                getLogger().info("Welcome " + user.getUsername());
                return true;
            } else {
                return false;
            }
        }
    }

    public boolean canChangePassword() {
        synchronized (operator.getLock()) {
            return operator.canChangePassword();
        }
    }

    public boolean isSessionActive() {
        return (this.workingUser != null);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -