Package info.jtrac.domain

Examples of info.jtrac.domain.Space


   
    public static ItemSearch getItemSearch(User user, PageParameters params, Jtrac jtrac) throws JtracSecurityException {
        long spaceId = params.getLong("s", -1);       
        ItemSearch itemSearch = null;
        if(spaceId > 0) {           
            Space space = jtrac.loadSpace(spaceId);
            if(!user.isAllocatedToSpace(space.getId())) {
                throw new JtracSecurityException("User not allocated to space: " + spaceId + " in URL: " + params);
            }
            itemSearch = new ItemSearch(space);           
        } else {
            itemSearch = new ItemSearch(user);
View Full Code Here


            add(new ListView("spaces", allowedSpaces) {
                protected void populateItem(ListItem listItem) {
                    long spaceId = (Long) listItem.getModelObject();   
                    List<UserSpaceRole> usrs = spaceRolesMap.get(spaceId);
                    // space can be null for "all spaces" role (prefixCode used in map = "")
                    final Space space = usrs.get(0).getSpace();                    
                    if(space != null && space.getId() == selectedSpaceId) {
                        listItem.add(new SimpleAttributeModifier("class", "selected"));
                    } else if(listItem.getIndex() % 2 == 1) {
                        listItem.add(sam);
                    }                                                                                                        
                    if(space == null) {                       
                        listItem.add(new Label("name", localize("user_allocate_space.allSpaces")));
                        listItem.add(new WebMarkupContainer("prefixCode").setVisible(false));                       
                    } else {
                        listItem.add(new Label("name", space.getName()));
                        listItem.add(new Link("prefixCode") {
                            public void onClick() {
                                if(previous instanceof SpaceAllocatePage) { // prevent recursive stack buildup
                                    previous = null;
                                }                               
                                setResponsePage(new SpaceAllocatePage(space.getId(), UserAllocatePage.this, userId));
                            }
                        }.add(new Label("prefixCode", space.getPrefixCode())));
                    }
                    listItem.add(new RoleDeAllocatePanel("roleDeAllocatePanel", usrs));                   
                }
            });                      
           
            List<Space> spaces = getJtrac().findSpacesNotFullyAllocatedToUser(user.getId());
           
            if(!isPrincipalSuperUser) {
                // not super user, show only spaces which can admin
                Set<Space> set = new HashSet(spaces);               
                List<Space> allowed = new ArrayList<Space>();
                // also within these spaces may be fully allocated, so trim
                for(Space s : principal.getSpacesWhereRoleIsAdmin()) {
                    if(set.contains(s)) {
                        allowed.add(s);
                    }
                }
                spaces = allowed;
            }
           
            DropDownChoice spaceChoice = new DropDownChoice("space", spaces, new IChoiceRenderer() {
                public Object getDisplayValue(Object o) {
                    Space space = (Space) o;
                    return space.getName() + " [" + space.getPrefixCode() + "]";
                }
                public String getIdValue(Object o, int i) {
                    return ((Space) o).getId() + "";
                }
            });           
            spaceChoice.setNullValid(true);
           
            add(spaceChoice);
           
            spaceChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
                protected void onUpdate(AjaxRequestTarget target) {
                    Space s = (Space) getFormComponent().getConvertedInput();
                    if (s == null) {
                        roleAllocatePanel.setChoices(new ArrayList<String>());
                        allocateButton.setEnabled(false);
                    } else {
                        Space temp = getJtrac().loadSpace(s.getId());
                        // populate choice, enable button etc
                        initRoleChoice(temp);
                    }
                    target.addComponent(roleAllocatePanel);
                    target.addComponent(allocateButton);
View Full Code Here

       
        final SimpleAttributeModifier sam = new SimpleAttributeModifier("class", "alt");
       
        ListView listView = new ListView("spaces", spaceListModel) {
            protected void populateItem(ListItem listItem) {               
                final Space space = (Space) listItem.getModelObject();               
                if (selectedSpaceId == space.getId()) {
                    listItem.add(new SimpleAttributeModifier("class", "selected"));
                } else if(listItem.getIndex() % 2 == 1) {
                    listItem.add(sam);
                }                                
                listItem.add(new Label("prefixCode", new PropertyModel(space, "prefixCode")));
                listItem.add(new Label("name", new PropertyModel(space, "name")));
                Link edit = new Link("edit") {
                    public void onClick() {
                        Space temp = getJtrac().loadSpace(space.getId());
                        temp.getMetadata().getXmlString()// hack to override lazy loading
                        SpaceFormPage page = new SpaceFormPage(temp);
                        page.setPrevious(SpaceListPage.this);
                        setResponsePage(page);                       
                    }                   
                };
View Full Code Here

                /*
                 * ===================================================
                 * Assigned to
                 * ===================================================
                 */
                Space space = item.getSpace();
                List<UserSpaceRole> userSpaceRoles = getJtrac().findUserRolesForSpace(space.getId());
                List<User> assignable = UserUtils.filterUsersAbleToTransitionFrom(userSpaceRoles, space, State.OPEN);
                DropDownChoice choice = new DropDownChoice("assignedTo", assignable, new IChoiceRenderer() {
                    public Object getDisplayValue(Object o) {
                        return ((User) o).getName();
                    }
View Full Code Here

    public DashboardRowExpandedPanel(String id, final UserSpaceRole usr, final Counts counts) {       
       
        super(id);
        setOutputMarkupId(true);
       
        final Space space = usr.getSpace();
        final User user = usr.getUser();
       
        final Map<Integer, String> states = new TreeMap(space.getMetadata().getStatesMap());   
        states.remove(State.NEW);
        int rowspan = states.size() + 1; // add one totals row also
        final SimpleAttributeModifier sam = new SimpleAttributeModifier("rowspan", rowspan + "");
        List<Integer> stateKeys = new ArrayList<Integer>(states.keySet());                                               
       
        add(new ListView("rows", stateKeys) {
           
            protected void populateItem(ListItem listItem) {                               
               
                if (listItem.getIndex() == 0) { // rowspan output only for first row           
                   
                    WebMarkupContainer spaceCell = new WebMarkupContainer("space");    
                    spaceCell.add(sam);
                    listItem.add(spaceCell);
                                     
                    spaceCell.add(new Label("name", space.getName()));
                    spaceCell.add(new Label("prefixCode", space.getPrefixCode()));
                   
                    WebMarkupContainer newColumn = new WebMarkupContainer("new");
                    newColumn.add(sam);  
                    listItem.add(newColumn);
                   
View Full Code Here

            add(new TextArea("comment").setRequired(true).add(new ErrorHighlighter()));
            // custom fields ===================================================
            User user = getPrincipal();
            add(new CustomFieldsFormPanel("fields", model, item, user));
            // =================================================================
            final Space space = item.getSpace();
            final List<UserSpaceRole> userSpaceRoles = getJtrac().findUserRolesForSpace(space.getId());           
            // assigned to =====================================================
            final WebMarkupContainer border = new WebMarkupContainer("border");
            border.setOutputMarkupId(true);
            final WebMarkupContainer hide = new WebMarkupContainer("hide");
            border.add(hide);                      
            final List<User> emptyList = new ArrayList<User>(0)// will be populated over Ajax
            assignedToChoice = new DropDownChoice("assignedTo", emptyList, new IChoiceRenderer() {
                public Object getDisplayValue(Object o) {
                    return ((User) o).getName();
                }
                public String getIdValue(Object o, int i) {
                    return ((User) o).getId() + "";
                }
            });
            assignedToChoice.setOutputMarkupId(true);
            assignedToChoice.setVisible(false);
            assignedToChoice.setNullValid(true);           
            border.add(new ErrorHighlighter(assignedToChoice));
            border.add(assignedToChoice);
            add(border);
            // status ==========================================================
            final Map<Integer, String> statesMap = item.getPermittedTransitions(user);
            List<Integer> states = new ArrayList(statesMap.keySet());
            statusChoice = new IndicatingDropDownChoice("status", states, new IChoiceRenderer() {
                public Object getDisplayValue(Object o) {
                    return statesMap.get(o);
                }
                public String getIdValue(Object o, int i) {
                    return o.toString();
                }
            });
            statusChoice.setNullValid(true);
            statusChoice.add(new ErrorHighlighter());
            statusChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
                protected void onUpdate(AjaxRequestTarget target) {
                    Integer selectedStatus = (Integer) getFormComponent().getConvertedInput();
                    if (selectedStatus == null) {                       
                        assignedToChoice.setVisible(false);
                        hide.setVisible(true);
                    } else {
                        List<User> assignable = UserUtils.filterUsersAbleToTransitionFrom(userSpaceRoles, space, selectedStatus);
                        assignedToChoice.setChoices(assignable);
                        assignedToChoice.setVisible(true);
                        hide.setVisible(false);
                    }
                    target.addComponent(border);
                }
            });
            add(statusChoice);
            // notify list =====================================================
            List<ItemUser> choices = UserUtils.convertToItemUserList(userSpaceRoles);
            ListMultipleChoice itemUsers = new JtracCheckBoxMultipleChoice("itemUsers", choices, new IChoiceRenderer() {
                public Object getDisplayValue(Object o) {
                    return ((ItemUser) o).getUser().getName();
                }
                public String getIdValue(Object o, int i) {
                    return ((ItemUser) o).getUser().getId() + "";
                }
            }, true);
            add(itemUsers);
            // attachment ======================================================
            fileUploadField = new FileUploadField("file");
            add(fileUploadField);
            setMaxSize(Bytes.megabytes(getJtrac().getAttachmentMaxSizeInMb()));
            // send notifications===============================================
            add(new CheckBox("sendNotifications"));
            // validation that assignedTo is not null if status is not null and not CLOSED
            // have to use FormValidator because this is conditional validation across two FormComponents
            add(new AbstractFormValidator() {
                public FormComponent[] getDependentFormComponents() {
                    // actually we depend on assignedToChoice also, but wicket logs a warning when the
                    // component is not visible but we are doing ajax.  anyway we use assignedToChoice.getInput()
                    // not assignedToChoice.convertedInput() so no danger there
                    return new FormComponent[] {statusChoice};
                }
                public void validate(Form unused) {
                    if(assignedToChoice.getInput() == null || assignedToChoice.getInput().trim().length() == 0) {
                        Integer i = (Integer) statusChoice.getConvertedInput();
                        if (i != null && i != State.CLOSED) {
                            // user may have customized the name of the CLOSED State e.g. for i18n
                            // so when reporting the error, use the display name
                            String closedDisplayName = space.getMetadata().getStatusValue(State.CLOSED);
                            assignedToChoice.error(localize("item_view_form.assignedTo.error", closedDisplayName));
                        }
                    }
                }
            });
View Full Code Here

   
    public HeaderPanel() {
        super("header");
       
        final User user = getPrincipal();
        final Space space = getCurrentSpace();
        final List<Space> spaces = new ArrayList(user.getSpaces());
       
        add(new Link("dashboard") {
            public void onClick() {
                setCurrentSpace(null);
                setResponsePage(DashboardPage.class);
            }           
        });
       
        if (space == null) {
            add(new WebMarkupContainer("spaceName").setVisible(false));
            add(new WebMarkupContainer("new").setVisible(false));
            add(new Link("search") {
                public void onClick() {                   
                    // if only one space don't use generic search screen
                    if(spaces.size() == 1) {
                        Space current = spaces.get(0);
                        setCurrentSpace(current);                       
                    } else {
                        setCurrentSpace(null); // may have come here with back button!                       
                    }
                    setResponsePage(ItemSearchFormPage.class);
View Full Code Here

    public JtracTest(String name) {
        super(name);
    }
   
    private Space getSpace() {
        Space space = new Space();
        space.setPrefixCode("TEST");
        space.setName("Test Space");
        return space;
    }
View Full Code Here

        User user2 = dao.findUsersByEmail("test@jtrac.com").get(0);
        assertTrue(user2.getLoginName().equals("test"));
    }
   
    public void testUserSpaceRolesInsert() {
        Space space = getSpace();
        Metadata metadata = getMetadata();
       
        space.setMetadata(metadata);
        jtrac.storeSpace(space);
       
        User user = new User();
        user.setLoginName("test");
       
        user.addSpaceWithRole(space, "ROLE_TEST");
        jtrac.storeUser(user);
       
        User u1 = jtrac.loadUser("test");
       
        GrantedAuthority[] gas = u1.getAuthorities();
        assertEquals(1, gas.length);       
        assertEquals("ROLE_TEST:TEST", gas[0].getAuthority());
       
        List<UserSpaceRole> userSpaceRoles = jtrac.findUserRolesForSpace(space.getId());
        assertEquals(1, userSpaceRoles.size());
        UserSpaceRole usr = userSpaceRoles.get(0);
        assertEquals("test", usr.getUser().getLoginName());
        assertEquals("ROLE_TEST", usr.getRoleKey());
       
        List<User> users = jtrac.findUsersForUser(u1);
        assertEquals(1, users.size());
       
        List<User> users2 = jtrac.findUsersForSpace(space.getId());
        assertEquals(1, users2.size());
       
    }
View Full Code Here

        assertEquals(1, set.size());       
        assertTrue(set.contains("ROLE_ADMIN"));
    }
   
    public void testItemInsertAndCounts() {
        Space s = getSpace();
        jtrac.storeSpace(s);
        User u = new User();
        u.setLoginName("test");
        u.addSpaceWithRole(s, "DEFAULT");
        jtrac.storeUser(u);
        Item i = new Item();
        i.setSpace(s);
        i.setAssignedTo(u);
        i.setLoggedBy(u);
        i.setStatus(State.CLOSED);
        jtrac.storeItem(i, null);
        assertEquals(1, i.getSequenceNum());
       
        CountsHolder ch = jtrac.loadCountsForUser(u);
        assertEquals(1, ch.getTotalAssignedToMe());
        assertEquals(1, ch.getTotalLoggedByMe());
        assertEquals(1, ch.getTotalTotal());
       
        Counts c = ch.getCounts().get(s.getId());
        assertEquals(1, c.getLoggedByMe());
        assertEquals(1, c.getAssignedToMe());
        assertEquals(1, c.getTotal());
    }
View Full Code Here

TOP

Related Classes of info.jtrac.domain.Space

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.