                 log.warn "unexpected category id: #{cid}"
             else
                 o.categoryId = categoryMap[cid]
+
+        if o.operationTypeID?
+            oid = o.operationTypeID
+            if not opTypeMap[oid]?
+                log.warn "unexpected operation type id: #{oid}"
+            else
+                o.operationTypeID = opTypeMap[oid]
+
         # Strip away id
         o.id = undefined
 

                if err?
                    return h.sendErr res, "When creating category: #{err.toString()}"

                async.eachSeries all.operations, importOperation, (err) ->
                    if err?
                        return h.sendErr res, "When creating operation: #{err.toString()}"

                    async.each all.settings, importSetting, (err) ->
                        if err?
                            return h.sendErr res, "When creating setting: #{err.toString()}"

                        log.info "Import finished with success!"
                        res.sendStatus 200


            categoryMap[catId] = created.id
            cb null, created

    opTypeMap = {}
    importOperationType = (type, cb) ->
        opTypeId = type.id
        type.id = undefined
        OperationType.create type, (err, created) ->
            if err?
                return cb err
            opTypeMap[opTypeId] = created.id
            cb null, created

    importOperation = (op, cb) ->
        if op.categoryId?
            if not categoryMap[op.categoryId]?
                return h.sendErr res, "unknown category #{op.categoryId}", 400, "unknown category"
            op.categoryId = categoryMap[op.categoryId]

        if op.operationTypeID?
            if not opTypeMap[op.operationTypeID]?
                return h.sendErr res, "unknown operation type #{op.operationTypeID}", 400, "unknown operation type"
            op.operationTypeID = opTypeMap[op.operationTypeID]

        Operation.create op, cb

    importSetting = Config.create.bind Config

    log.info """Importing:
    accesses:        #{all.accesses.length}
    accounts:        #{all.accounts.length}
    categories:      #{all.categories.length}
    operation-types: #{all.operationtypes.length}
    operations:      #{all.operations.length}
    settings:        #{all.settings.length}
    """

    async.each all.accesses, importAccess, (err) ->
