Search in sources :

Example 1 with Guardian

use of eu.ggnet.saft.core.auth.Guardian in project dwoss by gg-net.

the class AutoLoginLogoutHandler method showAuthenticator.

@Override
public void showAuthenticator() {
    // When the Dialog is already open, return.
    if (dialog != null)
        return;
    Guardian accessCos = Dl.local().lookup(Guardian.class);
    accessCos.logout();
    dialog = new AutoLogoutDialog(UiCore.getMainFrame(), accessCos.getOnceLoggedInUsernames());
    dialog.setVisible(true);
    dialog = null;
}
Also used : Guardian(eu.ggnet.saft.core.auth.Guardian)

Example 2 with Guardian

use of eu.ggnet.saft.core.auth.Guardian in project dwoss by gg-net.

the class ConsumerFactoryOfStockTransactions method of.

@Override
public List<DescriptiveConsumer<PicoUnit>> of(PicoUnit t) {
    StockAgent stockAgent = Dl.remote().lookup(StockAgent.class);
    StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(t.uniqueUnitId);
    if (su == null || su.isInTransaction())
        return Collections.EMPTY_LIST;
    Guardian guardian = Dl.local().lookup(Guardian.class);
    if (!guardian.hasRight(CREATE_TRANSACTION_FOR_SINGLE_UNIT))
        return Collections.EMPTY_LIST;
    return stockAgent.findAll(Stock.class).stream().filter(s -> !s.equals(su.getStock())).map(destination -> {
        return new DescriptiveConsumer<>("Umfuhr von " + su.getStock().getName() + " nach " + destination.getName(), (PicoUnit t1) -> {
            Ui.exec(() -> {
                Ui.build().dialog().eval(() -> new CreateQuestionModel(su, destination, "Umfuhr direkt durch Nutzer erzeugt"), () -> new CreateQuestionView()).opt().map(v -> ReplyUtil.wrap(() -> Dl.remote().lookup(StockTransactionProcessor.class).perpareTransfer(v.stockUnits, v.destination.getId(), Dl.local().lookup(Guardian.class).getUsername(), v.comment))).filter(Ui.failure()::handle).ifPresent(u -> Ui.build().alert("Umfuhr angelegt"));
            });
        });
    }).collect(Collectors.toList());
}
Also used : StockTransactionProcessor(eu.ggnet.dwoss.stock.ee.StockTransactionProcessor) DescriptiveConsumer(eu.ggnet.saft.core.ops.DescriptiveConsumer) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) Ui(eu.ggnet.saft.Ui) Collectors(java.util.stream.Collectors) Dl(eu.ggnet.saft.Dl) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) Guardian(eu.ggnet.saft.core.auth.Guardian) List(java.util.List) ReplyUtil(eu.ggnet.dwoss.common.ReplyUtil) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) DescriptiveConsumerFactory(eu.ggnet.saft.core.ops.DescriptiveConsumerFactory) CREATE_TRANSACTION_FOR_SINGLE_UNIT(eu.ggnet.dwoss.rights.api.AtomicRight.CREATE_TRANSACTION_FOR_SINGLE_UNIT) Collections(java.util.Collections) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) Guardian(eu.ggnet.saft.core.auth.Guardian) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 3 with Guardian

use of eu.ggnet.saft.core.auth.Guardian in project dwoss by gg-net.

the class CreateSimpleActionTryout method tryout.

@Test
public void tryout() throws InterruptedException {
    JPanel p = new JPanel();
    JButton b = new JButton("Press to close");
    b.setPreferredSize(new Dimension(200, 50));
    CountDownLatch l = new CountDownLatch(1);
    b.addActionListener(e -> {
        l.countDown();
    });
    p.add(new JButton(new CreateSimpleAction()));
    p.add(b);
    Dl.remote().add(StockAgent.class, new StockAgent() {

        @Override
        public <T> List<T> findAll(Class<T> entityClass) {
            if (entityClass.equals(Stock.class))
                return (List<T>) Arrays.asList(new Stock(0, "Rotes Lager"), new Stock(1, "Blaues Lager"));
            return null;
        }

        @Override
        public List<StockUnit> findStockUnitsByRefurbishIdEager(List<String> refurbishIds) {
            if (refurbishIds.contains("1")) {
                Stock s = new Stock(0, "Lager1");
                StockUnit s1 = new StockUnit("1", "Gerät Eins", 1);
                s1.setStock(s);
                return Arrays.asList(s1);
            }
            return Collections.EMPTY_LIST;
        }

        // <editor-fold defaultstate="collapsed" desc="Unused Methodes">
        @Override
        public StockUnit findStockUnitByUniqueUnitIdEager(Integer uniqueUnitId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockUnit findStockUnitByRefurbishIdEager(String refurbishId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T persist(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T merge(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> void delete(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockTransaction findOrCreateRollInTransaction(int stockId, String userName, String comment) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> long count(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAll(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    Dl.remote().add(StockTransactionProcessor.class, new StockTransactionProcessor() {

        @Override
        public SortedMap<Integer, String> perpareTransfer(List<StockUnit> stockUnits, int destinationStockId, String arranger, String comment) throws UserInfoException {
            SortedMap<Integer, String> r = new TreeMap<>();
            r.put(1, "1");
            return r;
        }

        // <editor-fold defaultstate="collapsed" desc="Unused Methodes">
        @Override
        public List<Integer> rollIn(List<StockTransaction> detachtedTransactions, String arranger) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void cancel(StockTransaction transaction, String arranger, String comment) throws UserInfoException {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void commission(List<StockTransaction> transactions, String picker, String deliverer) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void receive(List<StockTransaction> transactions, String deliverer, String reciever) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void removeFromPreparedTransaction(String refurbishId, String arranger, String comment) throws UserInfoException {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    Guardian guardianMock = mock(Guardian.class);
    given(guardianMock.getUsername()).willAnswer(i -> "Testuser");
    Dl.local().add(Guardian.class, guardianMock);
    UiCore.startSwing(() -> p);
    l.await();
}
Also used : JPanel(javax.swing.JPanel) JButton(javax.swing.JButton) StockTransactionType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionType) Guardian(eu.ggnet.saft.core.auth.Guardian) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) StockTransactionStatusType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Dimension(java.awt.Dimension) CountDownLatch(java.util.concurrent.CountDownLatch) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) LockModeType(javax.persistence.LockModeType) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) CreateSimpleAction(eu.ggnet.dwoss.stock.transactions.CreateSimpleAction) StockTransactionProcessor(eu.ggnet.dwoss.stock.ee.StockTransactionProcessor) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Example 4 with Guardian

use of eu.ggnet.saft.core.auth.Guardian in project dwoss by gg-net.

the class ShowRightsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Ui.exec(() -> {
        Ui.build().fx().show(() -> {
            StringBuilder sb = new StringBuilder();
            Guardian accessCos = Dl.local().lookup(Guardian.class);
            sb.append("<html><body><u>Benutzer:</u> <b>").append(accessCos.getUsername()).append("</b><br /><u>Berechtigungen</u><ul>");
            for (Authorisation authorisation : accessCos.getRights()) {
                sb.append("<li>").append(authorisation.toName()).append("</li>");
            }
            sb.append("</ul></body></html>");
            return sb.toString();
        }, () -> new HtmlPane());
    });
}
Also used : Authorisation(eu.ggnet.saft.api.auth.Authorisation) Guardian(eu.ggnet.saft.core.auth.Guardian) HtmlPane(eu.ggnet.dwoss.util.HtmlPane)

Aggregations

Guardian (eu.ggnet.saft.core.auth.Guardian)4 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)2 StockTransactionProcessor (eu.ggnet.dwoss.stock.ee.StockTransactionProcessor)2 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)2 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)2 ReplyUtil (eu.ggnet.dwoss.common.ReplyUtil)1 CREATE_TRANSACTION_FOR_SINGLE_UNIT (eu.ggnet.dwoss.rights.api.AtomicRight.CREATE_TRANSACTION_FOR_SINGLE_UNIT)1 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)1 StockTransactionStatusType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType)1 StockTransactionType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionType)1 CreateSimpleAction (eu.ggnet.dwoss.stock.transactions.CreateSimpleAction)1 PicoUnit (eu.ggnet.dwoss.uniqueunit.api.PicoUnit)1 HtmlPane (eu.ggnet.dwoss.util.HtmlPane)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1 Dl (eu.ggnet.saft.Dl)1 Ui (eu.ggnet.saft.Ui)1 Authorisation (eu.ggnet.saft.api.auth.Authorisation)1 DescriptiveConsumer (eu.ggnet.saft.core.ops.DescriptiveConsumer)1 DescriptiveConsumerFactory (eu.ggnet.saft.core.ops.DescriptiveConsumerFactory)1 Dimension (java.awt.Dimension)1