Package org.zanata.lock

Examples of org.zanata.lock.Lock


    @Override
    @Restrict("#{s:hasRole('admin')}")
    public Response updateTranslationMemory(String slug, InputStream input)
            throws Exception {
        Lock tmLock = lockTM(slug);
        try {
            Optional<TransMemory> tm = transMemoryDAO.getBySlug(slug);
            tmxParser.parseAndSaveTMX(input, getTM(tm, slug));
            return Response.ok().build();
        } finally {
View Full Code Here


    }

    @Restrict("#{s:hasRole('admin')}")
    public Object deleteTranslationMemory(String slug)
            throws EntityMissingException {
        Lock tmLock = lockTM(slug);
        try {
            Optional<TransMemory> transMemory = transMemoryDAO.getBySlug(slug);
            if (transMemory.isPresent()) {
                transMemoryDAO.makeTransient(transMemory.get());
                return "Translation memory '" + slug + "' deleted";
View Full Code Here

     *
     * @param slug
     * @return
     */
    public Object deleteTranslationUnitsUnguarded(String slug) {
        Lock tmLock = lockTM(slug);
        try {
            int numDeleted = transMemoryDAO.deleteTransMemoryContents(slug);
            return numDeleted + " translation units deleted";
        } finally {
            lockManagerServiceImpl.release(tmLock);
View Full Code Here

        return AsyncTaskResult
                .taskResult(deleteTranslationUnitsUnguarded(slug));
    }

    private Lock lockTM(String slug) {
        Lock tmLock = new Lock("tm", slug);
        String owner = lockManagerServiceImpl.attainLockOrReturnOwner(tmLock);
        if (owner != null) {
            throw new ZanataServiceException("Translation Memory '" + slug
                    + "' is locked by user: " + owner, 503);
        }
View Full Code Here

    @Override
    @Transactional
    public HDocument saveDocument(String projectSlug, String iterationSlug,
            Resource sourceDoc, Set<String> extensions, boolean copyTrans,
            boolean lock) {
        Lock docLock = null;
        if (lock) {
            // Lock this document for push
            docLock =
                    new Lock(projectSlug, iterationSlug, sourceDoc.getName(),
                            "push");
            lockManagerServiceImpl.attain(docLock);
        }

        try {
View Full Code Here

            String iterationSlug, String docId, LocaleId locale,
            TranslationsResource translations, Set<String> extensions,
            MergeType mergeType, boolean lock,
            AsyncTaskHandle handle) {
        // Lock this document for push
        Lock transLock = null;
        if (lock) {
            transLock =
                    new Lock(projectSlug, iterationSlug, docId, locale, "push");
            lockManagerServiceImpl.attain(transLock);
        }

        List<String> messages = Lists.newArrayList();
        try {
View Full Code Here

    private LockManagerServiceImpl lockManagerService =
            new LockManagerServiceImpl();

    @Test
    public void simpleLock() {
        Lock l1 = new Lock("prop1", "prop2", "prop3");

        boolean lockAquired = lockManagerService.checkAndAttain(l1);

        assertThat(lockAquired, is(true));
View Full Code Here

        lockManagerService.release(l1);
    }

    @Test
    public void deniedLock() {
        Lock l1 = new Lock("prop1", "prop2", "prop3");
        Lock l1Eq = new Lock("prop1", "prop2", "prop3");
        Lock l2 = new Lock("prop1", "prop2");

        assertThat(l1, equalTo(l1Eq));

        boolean lockAquired = lockManagerService.checkAndAttain(l1);
        assertThat(lockAquired, is(true));
View Full Code Here

TOP

Related Classes of org.zanata.lock.Lock

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.