package org.sagebionetworks.dashboard.service;

import javax.annotation.Resource;

import org.sagebionetworks.dashboard.dao.RawAccessRecordDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("rawAccessRecordService")
public class RawAccessRecordService {

    private final Logger logger = LoggerFactory.getLogger(RawAccessRecordService.class);

    @Resource
    private RawAccessRecordDao rawAccessRecordDao;

    public void update(final String filePath, final String username, final String password) {
        try {
            rawAccessRecordDao.copy(filePath, username, password);
        } catch (Throwable exception) {
            logger.error("Failed to copy file " + filePath);
        }
    }
}

@@ -56,31 +56,108 @@
 java
-x.annotation.Resource;%0A
+.util.UUID;%0A%0Aimport javax.annotation.Resource;%0A%0Aimport org.sagebionetworks.dashboard.dao.LogFileDao;
 %0Aimp
@@ -483,16 +483,66 @@
 lass);%0A%0A
+    @Resource%0A    private LogFileDao logFileDao;%0A%0A
     @Res
@@ -705,13 +705,226 @@
     
-try %7B
+if (logFileDao.isCompleted(filePath)) %7B%0A            return;%0A        %7D%0A        String id = UUID.randomUUID().toString();%0A        try %7B%0A            // type 0 for access_record%0A            logFileDao.put(filePath, id, 0);
 %0A   
@@ -987,16 +987,51 @@
 sword);%0A
+            logFileDao.update(id);%0A
         
@@ -1058,24 +1058,157 @@
 xception) %7B%0A
+            // if it's not a duplicate file, log the error%0A            if (!exception.getMessage().contains(%22already exists%22)) %7B%0A    
             
@@ -1256,16 +1256,50 @@
 ePath);%0A
+            %7D%0A            return;%0A
         

check if the file is already copied