Search in sources :

Example 96 with Permissions

use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.

the class DataPointDao method copy.

@Override
public int copy(final int existingId, final String newXid, final String newName) {
    TransactionCallback<Integer> callback = new TransactionCallback<Integer>() {

        @Override
        public Integer doInTransaction(TransactionStatus status) {
            DataPointVO dataPoint = get(existingId);
            // Copy the vo
            DataPointVO copy = dataPoint.copy();
            copy.setId(Common.NEW_ID);
            copy.setXid(generateUniqueXid());
            copy.setName(dataPoint.getName());
            copy.setDeviceName(dataPoint.getDeviceName());
            copy.setDataSourceId(dataPoint.getDataSourceId());
            copy.setEnabled(dataPoint.isEnabled());
            copy.getComments().clear();
            // Copy the event detectors
            List<AbstractEventDetectorVO<?>> existing = EventDetectorDao.instance.getWithSourceId(EventType.EventTypeNames.DATA_POINT, dataPoint.getId());
            List<AbstractPointEventDetectorVO<?>> detectors = new ArrayList<AbstractPointEventDetectorVO<?>>(existing.size());
            for (AbstractEventDetectorVO<?> ed : existing) {
                AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) ed;
                ped.setId(Common.NEW_ID);
                ped.njbSetDataPoint(copy);
            }
            copy.setEventDetectors(detectors);
            Common.runtimeManager.saveDataPoint(copy);
            // Copy permissions.
            return copy.getId();
        }
    };
    return getTransactionTemplate().execute(callback);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) TransactionCallback(org.springframework.transaction.support.TransactionCallback) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus)

Aggregations

User (com.serotonin.m2m2.vo.User)61 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)43 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)40 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)36 ArrayList (java.util.ArrayList)27 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)20 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)17 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)16 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)15 HashMap (java.util.HashMap)15 List (java.util.List)14 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)10 ASTNode (net.jazdw.rql.parser.ASTNode)10 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)9 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)8 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)8 URI (java.net.URI)8 Map (java.util.Map)8 ResponseEntity (org.springframework.http.ResponseEntity)7